views:

236

answers:

2

Hi!

I am currently working with a codeigniter PHP based application and have come to the point where it's about to go off with multiple languages.

Is codeigniters own language class the most effective way to handle languages? Is there any specific language-tools/libraries that are commonly used in PHP apps?

Thanks!

+12  A: 

I've never used CI_Language but it appears to use language arrays to do the translation.

Overly simplified example of this type method:

$trans = array(
    'MAIN_TITLE' => 'Title Here'
);

echo $trans['MAIN_TITLE'];

Personally I find this really annoying because you're then editing views that are cluttered with array key names instead of useful text. Which can be quite annoying at times. Not to mention you have to remember which keys correlate to which strings if you are using them in multiple places.

I use Gettext which I find much easier. You just have to wrap your strings with the translate method: _(). Then once you're done with your app, you open up PoEdit and create the new language file. PoEdit will parse all of my source files looking for strings wrapped like this <?php echo _('Title here') ?> and insert them into the .po language file. You can then go string by string and translate the text easily within PoEdit. The benefit of this is you have the source translation right there within PoEdit, instead of a meaningless array key name in some include file

This all makes my life much easier in that I can update my language files every Friday with one click. Any new or modified translations will automatically be added to my language file, and any unused translations will automatically be removed. I send the files off to my 3 international branchs for translation, and my changes and updated language files are ready to be deployed Monday morning

Mark
Thanks for your answer, Mark. Very appreciated. Your approach using gettext is interesting! I am thinking about doing pretty much the same, but a database version which will be heavily cached and instead updated upon request.
Industrial
Would be really nice to see more examples on different approaches to this issue though, not saying that your solution is bad!
Industrial
You may want to download ZF and check out the various adapters for Zend_Translate: http://framework.zend.com/manual/en/zend.translate.adapter.html for some additional ideas. They pretty much cover all of the popular localization methods
Mark
Thanks Mark, will check Zend_translate out. Thanks a lot!
Industrial
+1  A: 

You may want to have a look into php intl library. http://php.net/intl

Srikanth