The code i run looks as the following:
...
$this->locale = da_DK;
...
putenv("LC_ALL=".$this->locale);
putenv('LANG='.$this->locale);
$res = setlocale(LC_ALL, $this->locale);
if($res != $this->locale){
throw new Exception("The language could not be set.");
}
bindtextdomain("domain", "./locale");
textdomain("domain");
echo setlocale(LC_MESSAGES, 0 );
echo ' ';
echo __('description');
Result running it through apache2 is:
da_DK Beskrivelse
Which is as we want.
Running it throgh cli:
da_DK Description
Which would have been correct if we had used english. The 'd' is upper case in the english translation and the lower case in the source (From out of context it seems a bit weird)
So gettext works as it can translate the string, but somehow it disregards that i changed locale in the script and chose the .po file from the english directory.
In case you wonder why i need locales on a cli script: The script is used to emails out invoices.
I use: Ubuntu 12.10, PHP 5.4.6-1ubuntu1, apache 2.2.22, and gettext 0.18.1.
You need to check if the bindtextdomain() points the same resource file from php-cli and php-apache. I suggest,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With