How to set up translations of a PHP project to correctly use Launchpad translations?

Asked by Emilien Klein

Launchpad uses the standard GNU Gettext directory and file layout [0].
PHP uses the commonly seen "xx_XX/LC_MESSAGES/messages.po" layout. This layout is [unfortunately] not supported by Launchpad [1].

I am currently working to get a new PHP project to host on Launchpad and one of my main arguments is the translation community. The project itself has not yet been internationalized, so I'm wondering if there's a way to force PHP to use the standard GNU Gettext directory and file layout.

Or maybe another project has found a way to handle these differences in layout? I have written a Python script [2] to do that for a Django application, has anybody ever heard of a similar script for PHP?

The reason I'm asking here is that I'm pretty sure other PHP projects have had to go through the same question when setting up their translations.

[0] https://help.launchpad.net/Translations/YourProject/ImportPolicy#Sample_directory_layout
[1] https://answers.launchpad.net/launchpad/+question/119443
[2] http://bazaar.launchpad.net/~itt-devs/issuetrackertracker/main/view/head:/po/translations-manager.py

Question information

Language:
English Edit question
Status:
Answered
For:
Launchpad itself Edit question
Assignee:
Данило Шеган Edit question
Last query:
Last reply:
Whiteboard:
2011-09-19 Assigned to Danilo.
Revision history for this message
Данило Шеган (danilo) said :
#1

There are multiple things you can do:

 1. Extend Launchpad to support the common PHP layout — I am sure many others would appreciate that, but it's probably out of your scope — remember that Launchpad itself is open source, and you can learn how to start contributing on https://dev.launchpad.net/ :)

 2. Keep PO files in a generic gettext layout, but compile them to MO files in PHP-structure. Eg. "po/de.po" is compiled with msgfmt to "de/LC_MESSAGES/messages.mo" (note the MO extension). This is what I'd recommend, also combined with php-gettext[1] :)

 3. You can use an emulation layer like php-gettext[1] to read MO files directly (well, you'd use gettext.php from the project), though do note that it's much slower than native C-based gettext; wordpress does something like that with their pomo library (a derivative of old versions of php-gettext), when you can put the files where you please — if you don't worry about performance too much (iow, you won't get more traffic than wordpress does :), this should be a good choice

 3. Keep a separate tree with "regular" gettext layout with translations for the PHP project, or simply keep symlinks in the tree to ensure there is a structure that Launchpad expects (eg. po/de.po links to de/LC_MESSAGES/messages.po); note that I haven't tried this and I am not sure symlinks will be properly picked up :)

[1]https://launchpad.net/php-gettext — as the author, I can recommend it if you do care about both performance and compatibility but then you'd still have to use the same old "unsupported" layout for MO files, because it ensures translations load even when gettext or locales are not available, and uses native compiled gettext calls whenever possible

Can you help with this problem?

Provide an answer of your own, or ask Emilien Klein for more information if necessary.

To post a message you must log in.