Localization/Translations

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
AlexC
Forum Commoner
Posts: 83
Joined: Mon May 22, 2006 10:03 am

Localization/Translations

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Why not support all three?
AlexC
Forum Commoner
Posts: 83
Joined: Mon May 22, 2006 10:03 am

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
AlexC
Forum Commoner
Posts: 83
Joined: Mon May 22, 2006 10:03 am

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm not talking about permanently, but "live" overrides, which is possible to do.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

function mytext($str) {
  if (has_xml_translation($str)) {
     return get_xml_translation($str);
  } else {
     return gettext($str);
  }
}
AlexC
Forum Commoner
Posts: 83
Joined: Mon May 22, 2006 10:03 am

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It's hard to say. Really, that depends on the host(s).
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
Post Reply