12

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 oks - 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.

Gazzer
  • 4,524
  • 10
  • 39
  • 49
Fluffy
  • 27,504
  • 41
  • 151
  • 234
  • Check the translation file. I think that gettext is more accurate than `File_Gettext_MO`. Look for the string `Cacnelled` therein, probably it's something you can see. You might want to add the part from your MO file to the question as well. – hakre Jun 17 '11 at 08:57
  • @hakre, I can see both `Cancelled` and `Storniert` in there. Which part of the file should I add? – Fluffy Jun 17 '11 at 09:31
  • What library is this? File_Gettext Pear? I can't find File_Gettext_MO anywhere. – Gazzer Aug 26 '11 at 04:42

1 Answers1

1

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

flindeberg
  • 4,887
  • 1
  • 24
  • 37
  • This doesn't seem to be a Windows issue, since there's the same script on the server with the same behavior. As you can see in the output, spaces are ok. Actually, I didn't find a solution for this - I'm just using DB + memcached now, which seems to work quite well. – Fluffy Jun 29 '11 at 07:31
  • Also, I tried to find some pattern in which the keys aren't working - like, multibyte character appears and all the subsequent keys are broken. But while the keys are alphabet ordered in the file, those which don't work are in random places. – Fluffy Jun 29 '11 at 07:35