Posted in localization
Wed, 14 Jun 2006 07:05:00 GMT
Playing around with browser locale settings and the resulting HTTP_ACCEPT_LANGUAGE values, I've started to realize that websites often don't fallback to the language if you are using a two part locale they don't support but they do support the language only. Let's say a browser has the following preferences set up:
A website that only has en and de will typically fail on en-us and then return German. My intuition tells me the server would be more user friendly if it parsed en-us to try the language portion, en, before moving on to the next locale but there would be situations where the user won't get exactly what s/he wants? What do you think? Should servers fallback from two part locales to a one part language or should it be up to the user to manage it correctly in their browser?
Posted in catalyst, perl, localization
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. http://www.mysite.cn) 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:
- string substitution
- multiple template sets
- 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?