Page 1 of 1

Localization/Translations

Posted: Sat Jun 30, 2007 6:56 am
by AlexC
Hey,

For a while now I've been wanting to support localizations/translations within my framework - but I just can't decide on the best way of doing it! The frameworks use is the backend of an open-source CMS I'm developing if that's any relevance. Anyway, here are the ways I can think of for localization:

Gettext
Advantages:
  • There are many web based (Launchpad for example) tools out there to help with translating the .po files (also a lot of applications as well)
  • It's the fastest way (after looking at some benchmarking) to provide localization
Disadvantages:
  • Requires the server to have the correct Locales installed
  • Requires PHP to be compiled with gettext support
  • Have to re-generate .mo files once you have edited the .po files - and if people want to just tweak a string and they don't have the tools to create the .mo it could be tricky
PHP Gettext (Gettext implementation written in PHP)
Advantages:
  • Again many web-based and applications to help translate .po files
  • Doesn't require the server to have Locales installed
  • No need for PHP gettext extension
Disadvantages:
  • Quite slow
  • Again, have to re-generate .mo files
Ini/XML File
Advantages:
  • Simple to use
  • No need to convert to another file type, just edit it and off you go!
  • Fast
Disadvantages:
  • No web-based or application to help translations
What do you think I should go with? I would really like to use the Translations part of Launchpad since I already use it a lot of Bugs and Features (Blueprints), it would make it a lot easier for people to translate my CMS - but is it worth using gettext just for that? Help!

Posted: Sat Jun 30, 2007 7:07 am
by feyd
Why not support all three?

Posted: Sat Jun 30, 2007 7:18 am
by AlexC
I _could_ support the first 2, however supporting all 3 would be a bad move. It would mean the translators would have to edit 2 lots of files, in 2 different places.

Posted: Sat Jun 30, 2007 7:24 am
by feyd
No it doesn't. ;)

ini/xml can be used for personal tweaks while gettext can be used for more "official" changes. It should be possible to mix the two by allowing the ini/xml override lines in the official text.

Posted: Sat Jun 30, 2007 7:29 am
by AlexC
You can't override the lines in the mo file, there is no way of getting to the strings of the .mo file other than trying to translate via _() or gettext() etc.

Posted: Sat Jun 30, 2007 7:34 am
by feyd
I'm not talking about permanently, but "live" overrides, which is possible to do.

Posted: Sat Jun 30, 2007 9:09 am
by Weirdan

Code: Select all

function mytext($str) {
  if (has_xml_translation($str)) {
     return get_xml_translation($str);
  } else {
     return gettext($str);
  }
}

Posted: Sat Jun 30, 2007 9:28 am
by AlexC
Ah I see what you mean, Feyd - I'll look more into that.

My only concern with using Gettext is the server has to have the locales installed - if it doesn't, it will show the strings in English, how likely is it that servers don't have the correct locales installed?

Posted: Sat Jun 30, 2007 9:54 am
by feyd
It's hard to say. Really, that depends on the host(s).

Posted: Mon Jul 02, 2007 3:39 am
by CoderGoblin
The Zend Framework Localisation documentation mentions the following possibilities:

Code: Select all

PHP Array : Small pages; simplest usage; only for programmers
Csv       : Simple text file format; very fast; possible problems with unicode characters
Gettext   : GNU standard for linux; very fast; thread-safe; needs tools for translation
TMX       : Industry standard for inter application translation; XML format; human readable
QT        : (qt linguist (*.ts) files) Cross platform application framework; XML format; human readable
XLIFF     : A simpler format as TMX but related to it; XML format; human readable
Others    : *.sql, *.tbx, *.qt
Not sure if it is of use but may provide inspiration of other things to look at. In a lot of systems a combination of methods may work best.