catalyst iconperl icon

Localization / Internationalization with Catalyst

Posted in , , Wed, 14 Jun 2006 06:06:00 GMT

I played with Catalyst::Plugin::I18N today to test returning text according to the user's language. This is called internationalization (I18N) or localization (L10N). I prefer the term localization when customizing output for users for this (and internationalization for storing multi-lingual data in the backend) but the definition is subject to debate and both are used. It seems there are two stages to L10N: locale detection and the localization.

C::P::I18N can do dection based on an explicit setting:

$c->languages( ['de'] );

or automatic browser detection based on the browser's HTTP_ACCEPT_LANGUAGE. C::P::I18N does the localization portion using string substitution. To set this up put your string definitions in the your mo/po or Maketext classes and then localize in the View, for example using TT:

[% c.loc('Hello World') %]

Also make sure to set the Vary header to assist with caching:

# Covers one or more Vary headers
    Vary => 'Accept-Language'

# If you only have one Vary header
$c->res->header( Vary => 'Accept-Language' );

The Vary header should theoretically handle proxy caching though these servers are typically out of your control and cannot be guaranteed to recognize and process the header.

The other popular detection option seems to be to put the locale in the URI, either in the domain name (e.g. or in the path / query string, as opposed to reading a HTTP request parameter.

Cal Henderson's Building Scalable Websites O'Reilly book talks about Localization and mentions three methods:

  1. string substitution
  2. multiple template sets
  3. multiple frontends

Cal mentions all three methods are hard and doesn't give an outright recommendation. He does, however, lists problems with string substitution and multple template sets but not multiple frontends so perhaps he's implicitly recommending the latter. He doesn't talk about detection methods. At first I was very excited to get Cal's book because I thought he would make outright recommendations. I'm starting to realize it's more of a primer and you have to tease out the best option.

Do you L10N or I18N? If so, how do you do it? / Internationalization with Catalyst digg:Localization / Internationalization with Catalyst reddit:Localization / Internationalization with Catalyst spurl:Localization / Internationalization with Catalyst wists:Localization / Internationalization with Catalyst simpy:Localization / Internationalization with Catalyst newsvine:Localization / Internationalization with Catalyst blinklist:Localization / Internationalization with Catalyst furl:Localization / Internationalization with Catalyst fark:Localization / Internationalization with Catalyst blogmarks:Localization / Internationalization with Catalyst Y!:Localization / Internationalization with Catalyst smarking:Localization / Internationalization with Catalyst magnolia:Localization / Internationalization with Catalyst segnalo:Localization / Internationalization with Catalyst



  1. Dist said 4 months later:


    I’m actually trying to use C::P::I18N, but it doesn’t actually come with very good instructions. It really doesn’t say where you should place your localized files and what exactly is needed to make it work.

    If you know, would you like to document that somewhere? (Example project would be superb =)

    Anyway, I might do that once I’ve dug through that thing.

    Very informative site, cheers!

  2. Harper said about 1 year later:

    You can see info about *.mo file in plugin source code – if use Data::Dumper

(leave url/email »)

   Comment Markup Help Preview comment