[Catalyst] I18N with variables

Ton Voon tonvoon at gmail.com
Fri Aug 6 23:03:44 GMT 2010


On 6 Aug 2010, at 15:57, Bill Moseley wrote:

> I've been arguing with work about how to key our text.  So far we  
> continue to use the English in the loc() tags in the templates, and  
> then the I18N team uses a script to pull out this text which gets  
> sent to translation services.

For Opsview (http://opsview.com), we decided early on to use message  
ids. I'm very glad of this decision (after pain in my work on the  
Nagios Plugins using English text as the key).

After chatting to a Java guy who already implemented i18n in his app,  
we went with a dotted notation like:

[% c.loc("ui.admin.host.edit.label.hostaddress") %]

The dotted notation is good because it gives a pretty good idea where  
in the app this text will be found. The last part can be as complex as  
you like to describe the content. Variables work with:

[% c.loc("ui.admin.host.edit.label.numberOfAddresses [_1]",  
num_addresses) %]

Obviously, there needs to be an English translation. This is when I  
spent about 10 hours of my life trying to work out how  
Locale::Maketext::Simple was not doing a fallback as I expected. A  
patch was made and thankfully this works properly now if you set  
your .po file to be called i_default.po: http://cpansearch.perl.org/src/JESSE/Locale-Maketext-Simple-0.19/Changes

I run a make gettext in my cat app that calls xgettext.pl and some  
other perl code to check for missing strings in i_default.po. It also  
updates all our language files with any new msgids but sets msgstr to  
"". This is good because: (1) Locale::Maketext::Simple will now  
fallback to i_default.po and (2) anyone translating the .po files can  
easily see which strings still need translating.

So overall I think our workflow is pretty good. I can write a Cat  
advent calendar entry for this if interested.

Ton




More information about the Catalyst mailing list