Viewed   62 times

I'm building a Open Source product and I thinking about Localization, I've read about gettext but there seems to be a lot of problem to get it to work in different systems (servers,os etc).

How would you handle this? Is there a secure way to help gettext work on several systems? Perhaps it already is?

Regards from Sweden / Tobias

 Answers

4

I recommend you take a look at Zend_translate, Zend_locale and Zend_Date. I'm only starting to dabble with them myself, but to me, they already look like a really good, clean and modern solution to internationalization, in contrast to the chaos that is gettext.

The introduction to Zend_translate lists a number of strong arguments why to choose it (or something similar) over gettext.

In multilingual applications, the content must be translated into several languages and display content depending on the user's language. PHP offers already several ways to handle such problems, however the PHP solution has some problems:

Inconsistent API: There is no single API for the different source formats. The usage of gettext for example is very complicated.

PHP supports only gettext and native array: PHP itself offers only support for array or gettext. All other source formats have to be coded manually, because there is no native support.

No detection of the default language: The default language of the user cannot be detected without deeper knowledge of the backgrounds for the different web browsers.

Gettext is not thread-safe: PHP's gettext library is not thread safe, and it should not be used in a multithreaded environment. This is due to problems with gettext itself, not PHP, but it is an existing problem.

Friday, October 28, 2022
 
4

this is what im doing in my cms:

  • for each plugin/program/entity (you name it) i develop, i create a /translations folder.
  • i put there all my translations, named like el.txt, de.txt, uk.txt etc. all languages
  • i store the translation data in JSON, because its easy to store to, easy to read from and easiest for everyone to post theirs.
  • files can be easily UTF8 encoded in-file without messing with databases, making it possible to read them in file-mode. (just JSON.parse them)
  • on installation of such plugins, i just loop through all translations and put them in database, each language per table row. (etc. a data column of TEXT datatype)
  • for each page render i just query once the database for taking this row of selected language, and call json_decode() to the whole result to get it once; then put it in a $_SESSION so the next time to get flash-speed translated strings for current selected language.

the whole thing was developed having i mind both performance and compatibility.

in your case a row in such file could be like:

in en.txt

{"id":"LNG_1","str":"My word"}

in de.txt

{"id":"LNG_1","str":"Mein Wort"}

The current language could be stored in session like $_SESSION["language"]; and use that as starting point. Then, you can read translations like:

lang("LNG_1");
Monday, December 5, 2022
 
4

I would use gettext, since it's a mature system and provides features like singular/plural versions of translations. To be not dependant on the availability of the php extension, you should fall back to http://launchpad.net/php-gettext which provides a pure php implementation of gettext.

gettext has also the big advantage that dozens of tools exist that make it easy to translate those files.

Sunday, November 6, 2022
1

Ok, I basically ended up writing a mo file parser based on Zend's Gettext Adapter, as far as I know gettext is pretty much reliant upon the locale, so manually parsing the .mo file would save the hassle of running into odd circumstances with locale issues with setlocale. I also plan on parsing the Zend Locale data provided in the form of xml files.

Tuesday, November 29, 2022
 
lynnyi
 
1

A lot of CMS uses the array version. I have seen GetText as well for scalable applications. The array version is simpler especially when you want to manage the translation from a web interface.

It is a matter of preference of course.

Saturday, October 15, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :