Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gettext can't get setlocale() to work

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.

like image 758
Oriesok Vlassky Avatar asked Nov 20 '25 18:11

Oriesok Vlassky


1 Answers

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

like image 126
dsas Avatar answered Nov 23 '25 09:11

dsas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!