简体   繁体   中英

Most effective way working with multiple natural languages

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!

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM