views:

62

answers:

4

I am currently researching the best methods to integrate i18n into projects.

There's several methods I have thought of doing this, first being a database scheme to store the strings and relevant locale, but the problem with this is that it would not be that easy to select the strings, because i would not like to perform quesries like so:

SELECT text FROM locales WHERE locale = 'en_GB' AND text_id = 245543

Or

SELECT text FROM locales WHERE locale = 'en_GB' AND text_primary = 'hello'

The next method would be to store them within files such as locales/en_gb/login/strings.php and then try and access them via an class specifically developed like so:

$Language = Registry::Construct('Language',array('en_GB'));
echo $Language->login->strings->hello;

The issue with this is I would have to build a system that would update these files via an administration panel witch is very time consuming, not just building the system to manage the strings but actually managing the strings as the site grows

  • What other methods are there that will be beneficial for a large system
  • Is there any automated way to do 'Translation' as such
  • Should I stick with a database method and build a system for users to translate strings with rating / suggest better version ?
  • What systems have you tried in the past and should I look into them or totally avoid them.

Look forward to some answers :)

A: 

Have a look at the Gettext (http://php.net/manual/en/book.gettext.php) library.

Don't put your text into a database. That'll just make life hard on the translation team.

Graham Perks
+2  A: 

In addition to gettext already mentioned, PHP 5.3 has native Internationalization support

If that's not an option, consider using Zend Framework's Zend_Translate, Zend_Locale and related components for that. Zend_Translate supports a number of adapters, including but not limited to simple arrays, gettext, XmlTm and others.

Gordon
+1 For Zend_Translate.
wimvds
+2  A: 

I've implemented a XML translation utility as part of a bigger project. You can find it here, and a sample translation file is here (en_US).

halfdan
does it have UnitTests?
Gordon
They're not comitted yet. This project is relatively new, so I'm in the process of building up the framework. UnitTests are coming in the next few days.
halfdan
Great, i love the XML Formation rather then using things such as Arrays / objects, makes depth more simpler :) +1
RobertPitt
It should be pretty easy to write a GUI tool for translators too. Haven't had the time to write one though :)
halfdan
Update: Unit tests coming.
halfdan
A: 

The most impressive method to study is Drupal's implementation. Second best, would be Wordpress. Both use gettext and .pot/.po/.mo for localization. And, the good thing is that there is a beautiful Open Source .po editor called Poedit. It's available for Windows System users, which gives a wider appeal. It's also available for Mac and Linux. Check it out here: http://www.poedit.net/

UkrStackOverflow