gokuhs gokuhs - 8 months ago 39
PHP Question

php-gettext don't work in production server. (Ubuntu)

I'm having problems with gettext in PHP; i have two servers, one local (in which I development) in Windows (with vs.php) and works find, and other in Amazon EC2 (Ubuntu 12.04 updated), this is the production server and in this server the same code don't found.

This is my code:

I initialice the gettext with this.

function initialize_i18n($locale) {
$locales_root = "./librerias/noAuto/locale";
putenv("LC_ALL=" . $locale);
$domains = glob($locales_root.'/'.$locale.'/LC_MESSAGES/messages*.mo');
if (count ($domains) > 0)
$current = basename($domains[0],'.mo');
$timestamp = preg_replace('{messages-}i','',$current);
bind_textdomain_codeset( $current, "UTF-8" );
if ($locale == "en_US")
if( _("Modificar") === "Modify" ) {
$system->setDebug( "Translated correctly");
} else {
$system->setDebug( "Gettext don't working");

All files in my projects is coded in UTF-8 (in spanish Language), and the .mo and .po has been generated with poedit.

I try to reload apache service but did not work.

Any idea?


New day new ideas! I have a solution!

I you have the same problem, you need checks this steps.

1 - Your Linux have this language installed?

You can check with this:

 locale -a

If don't listed your language install it, for example you can install englsh localization with this:

 # aptitude install language-pack-en

And restart apache when finish.

2 - Your language code is correctly in PHP?

If you listed the list of language codes with locale -a you will see the language codes that you can use, for example, for english my system listed: [...] en_NG.utf8 en_NZ.utf8 en_PH.utf8 en_SG.utf8 en_US.utf8 [...] One my error are, I used "en_US" instead of "en_US.utf8".

3 - The folder have the SAME name as the language code. (My second error)

PD> Sorry for my bad english