Question

I am trying to translate a webpage to several languages. However, I can only make gettext work for spanish.

I am using this code:

$lang = "de_DE";
if (isset($_GET['lang'])) $lang = $_GET['lang'];
putenv("LC_ALL=$lang");
setlocale(LC_ALL, $lang);
bindtextdomain("messages", "locale");
bind_textdomain_codeset('messages', 'UTF-8');
textdomain("messages");

If I set $lang="es_ES" the strings get translated to spanish, but if I set $lang="de_DE" the translation doesn't work, I only see the default english version.

I think it may be something about my computer locale (I use Windows in spanish). I am working on Windows (using Wamp localhost) and I don't know whether I have to install something more and, if so, how to do it.

In case I have to do it, will it work in my online hosting without installing anything there?

Thank you! :)

Était-ce utile?

La solution

setlocale() has issues in Windows that is mentioned in PHP's official documentation itself:

The locale information is maintained per process, not per thread. If you are running PHP on a multithreaded server API like IIS or Apache on Windows, you may experience sudden changes in locale settings while a script is running, though the script itself never called setlocale(). This happens due to other scripts running in different threads of the same process at the same time, changing the process-wide locale using setlocale().

Windows users will find useful information about locale strings at Microsoft's MSDN website. Supported language strings can be found in the » language strings documentation and supported country/region strings in the » country/region strings documentation.

Mainly what you need to realize is that many PHP functions are wrappers over *ix OS program APIs. So they will work well in linux and other compatible OSes - not that well in Windows.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top