Some gettext keys aren't working for me - they show the key instead of the translation, though there is one. I'm making .mo file with PHP File_Gettext
Pear library, and it seems to be working ok, so I've made the following script to try out, which keys aren't working fine:
$locale = 'en_GB';
$domain = 'messages';
setlocale(LC_ALL, $locale);
putenv("LC_ALL=".$locale);
bindtextdomain($domain, "D:/_gt");
bind_textdomain_codeset($domain, 'UTF-8');
textdomain($domain);
$mocreator = new File_Gettext_MO();
$mocreator->load('D:/_gt/en_GB/LC_MESSAGES/messages.mo');
foreach ($mocreator->strings as $key => $value) {
if ($value == gettext($key)) {
var_dump("ok");
} else {
var_dump($key, $value, gettext($key));
}
}
From the output of the above I see that some keys work - I see a lot of ok
s - and some don't, yielding the following:
string 'Cancelled' (length=9)
string 'Storniert' (length=9)
string 'Cancelled' (length=9)
So there is translation in the file, but gettext fails to use them for some reason.
Now this is quite an old question, and I have have to point out that I'm not that well versed in gettext specific questions. But I've had some issues with array-keys as strings and encodings.
D:/_gt
gives me the impression that you are using Windows of some kind, and if I'm not mistaken all Windows versions use latin-1-"with-special-locale" as default. I believe that the issue could be encoding related since you are specifying the file as utf8 but I can't help you there without the .mo file. But try switching places of the putenv
and the setlocale
statements.
Or spaces missing? Could the correct key be " Cancelled"
?
But as someone said in the comments, this is just guesswork without the .mo file.
If you already found your own answer, please add it to help the rest of the Internets! :D
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