Reputation: 797
I use gettext localization like this
$lang = $_GET['lang'];
echo $lang;
putenv("LANG=$lang");
setlocale(LC_ALL, $lang);
bindtextdomain("messages", realpath("../locale"));
bind_textdomain_codeset("messages", "utf-8");
textdomain("messages");
...
echo _("Welcome!") etc.
I can see localization works, because the site can be seen translated in Slovak. However, no mather what is in the $lang variable, the site only is translated in Slovak or not translated at all.
Slovak means whatever .po and .mo files i have in 'sk' folder. I have tried putting different languages in the 'sk' folder, it works and I get different translations. But I cannot make it to take different folder, like 'en' or 'cs'. All other folders are ignored. What am I doing wrong?
P.S. setlocale() returns false, I can't figure out why but that's probably causing the trouble.
Upvotes: 3
Views: 4368
Reputation: 11
Well, there is another nasty hack:
On my system only en_DK.utf-8 is install and I'm not able to install any other langs.
So, i'm selecting the language by using the domain instead:
$lang = "en";
putenv("LANG=en_DK.utf8");
setlocale(LC_ALL, "en_DK.utf8");
bindtextdomain($lang, realpath("./locale"));
bind_textdomain_codeset($lang, "utf-8");
textdomain($lang);
The file location of the .mo files are like this:
./locale/en_DK.utf-8/LC_MESSAGES/en.mo
Upvotes: 0
Reputation: 1660
setlocale()
will return false if your system does not support that locale. You can see which locales your system supports by examining the output of locale -a
. The value that you pass in via the lang get var must match one of those locale names.
As Dan says, sk is probably your standard locale which is why that is used even if setlocale returns false..
Upvotes: 1