Re: How to do i18n better?

From: Date: Mon, 19 Apr 2010 13:56:32 +0000
Subject: Re: How to do i18n better?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-304209@lists.php.net to get a copy of this message
Michiel Sikma wrote:
On 19 April 2010 00:55, Andre Polykanine <andre@oire.org> wrote:
Now the i18n process is made as follows: we set a cookie on the site and depending on it we select the language to display the site in. We have three (currently) interface files: rus.lng, ukr.lng, and enu.lng (for English US). the format is the following: define ("MSG379", "Welcome!");
You might want to consider making the language dependent on the URL, e.g. http://site.com/ru/pagename for Russian. Doing it this way certainly isn't a bad solution, but I do strongly recommend against using define() and using anonymous translation keys. Usually, you have one base language (which is usually English due to its lack of special characters and ubiquity) from which you work. You then either simplify your keys, e.g. 'user_welcome' => 'Welcome, %1$s!', or make the keys the proper base language strings so you can wrap everything in a language function. In the latter case, you might have something like <p><?= _('Welcome, %1$s!', $username); ?></p>, and then if the current language is not English, the _() function will make the appropriate lookup.
Unless you have namespaces (and I can't remember if they completed namespaced based functions) then don't use something so commuon as a function named underscore :/ Cheers, Rob.

« previous php.general (#304209) next »