=head1 NAME HTML::FormFu::Manual::Unicode - Working with unicode =head1 DESCRIPTION Working with unicode. For a practical example, see the Catalyst application in the C directory in this distribution. =head1 ASSUMPTIONS In this tutorial, we're assuming that all encodings are UTF-8. It's relatively simple to combine different encodings from different sources, but that's beyond the scope of this tutorial. For simplicity, we're also going to assume that you're using L for your web-framework, L for your database ORM, L for your templating system, and YAML format C configuration files, with L installed. However, the principles we'll cover should translate to whatever technologies you chose to work with. =head1 BASICS To make it short and sweet: you must decode all data going into your program, and encode all data coming from your program. Skip to L if you want to see what you need to do without any other explanation. =head1 INPUT =head2 Input parameters from the browser If you're using C, L will decode all input parameters sent from the browser to your application - see L. If you're using some other framework or, in any case, you need to decode the input parameters yourself, please take a look at L. =head2 Data from the database If you're using L, L is likely the best options, as it will decode all input retrieved from the database - see L. In other cases (i.e. plain DBI), you still need to decode the string data coming from the database. This varies depending on the database server. For MySQL, for instance, you can use the C attribute: see L documentation for details. =head2 Your template files Set TT to decode all template files - see L. =head2 HTML::FormFu's own template files Set C to decode all template files - see L. =head2 HTML::FormFu form configuration files If you're using C config files, your files will automatically be decoded by C and C. If you have L config files, your files will automatically be decoded by C and C, which automatically sets L C<-UTF8> setting. =head2 Your perl source code Any perl source files which contain Unicode characters must use the L module. =head1 OUTPUT =head2 Data saved to the database With C, L will encode all data sent to the database - see L. =head2 HTML sent to the browser With C, L will encode all output sent from your application to the browser - see L. In other circumstances you need to be sure to output your Unicode (decoded) strings in UTF-8. To do this you can encode your output before it's sent to the browser with something like: use utf8; if ( $output && utf8::is_utf8($output) ){ utf8::encode( $output ); # Encodes in-place } Another option is to set the C for C: bindmode STDOUT, ':utf8'; However, be sure to do this B when sending UTF-8 data: if you're serving images, PFD files, etc, C should remain set to C<:raw>. =head1 CHANGES REQUIRED =head2 Catalyst Configuration Add L to the list of Catalyst plugins: use Catalyst qw( ConfigLoader Static::Simple Unicode ); =head2 DBIx::Class Configuration Add L to the list of components loaded, for each table that has columns storing unicode: __PACKAGE__->load_components( qw( UTF8Columns HTML::FormFu PK::Auto Core ) ); Pass each column name that will store unicode to C: __PACKAGE__->utf8_columns( qw( lastname firstname ) ); =head2 TT Configuration Tell TT to decode all template files, by adding the following to your application config in MyApp.pm package MyApp; use strict; use parent 'Catalyst'; use Catalyst qw( ConfigLoader ); MyApp->config({ 'View::TT' => { ENCODING => 'UTF-8', }, }); 1; =head2 HTML::FormFu Template Configuration Make C tell TT to decode all template files, by adding the following to your C Catalyst configuration file: package MyApp; use strict; use parent 'Catalyst'; use Catalyst qw( ConfigLoader ); MyApp->config({ 'Controller::HTML::FormFu' => { constructor => { tt_args => { ENCODING => 'UTF-8', }, }, }, }); 1; These above 2 examples should be combined, like so: package MyApp; use strict; use parent 'Catalyst'; use Catalyst qw( ConfigLoader ); MyApp->config({ 'Controller::HTML::FormFu' => { constructor => { tt_args => { ENCODING => 'UTF-8', }, }, }, 'View::TT' => { ENCODING => 'UTF-8', }, }); 1; =head1 AUTHORS Carl Franks C Michele Beltrame C (contributions) =head1 COPYRIGHT This document is free, you can redistribute it and/or modify it under the same terms as Perl itself. =cut