Skip to content
Advertisement

How to specify ordered variables in gettext .po files?

I have a multi-lingual site that uses Zend_Translate PHP arrays to handle the translations. It works fine, but I’m trying to convert to using gettext since that offers extra features.

However, I haven’t yet discovered the gettext equivalent of a feature that I liked in PHP array translations: n$ position specifier (example #4 of PHP sprintf).

I found a good example of what I want (notice how the order of the variables is different in English and Chinese):

JavaScript

But I haven’t gotten it working for me. My en/messages.po file has this:

JavaScript

and the PHP is this (which had worked for the array style of translations, and I don’t think it is supposed to change):

JavaScript

The HTML comes out wrong, like this:

JavaScript

How must I edit the .po file for this to work? Or should I not be using php-mo for compiling the .po into the .mo file?

Advertisement

Answer

My .po and .mo files worked (and my webpage looks good) after I tried commenting out this line of php-mo.php:

$x = str_replace('$', '\$', $x);

I’m actually not sure why that line was there at all, but removing it makes me nervous that I might be introducing bugs that I haven’t discovered yet. But at least it fixed the problems that I could see!

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement