So I'm testing a multilingual php/gettext site with poedit to manage translations. With the solution: Audero Shared Gettext, to deal with Apache problems on a shared hosting.
Basically my site is in French(fr_BE).
I have my structure for the different languages to translate (en_GB / nl_BE / it_IT) locale /language/LC_MESSAGE/.mo & .po
I have links with a $_GET[‘lang’] variable.
When I go to the links that should display the content in English everything seems to work, even going back and forth: FR/EN – EN-FR. But when I want to have the content in Dutch (nl_BE) or Italian (it_IT) it shows me the site in French.
I think the problem must come from the .mo files (DU/IT) compiling poorly, but I don't see where the error is
Do you have any idea or have you already encountered the problem?
Please remember, when you use gettext, you should configure your underlying OS with the target locales that you are going to use.
Basically, if you don't see your locale in the output of
locale -a, you will not be able to use your.mofiles even if they are placed in correct folders and the env variables are set correctly.Then, you don't add locales often, and generating a new locale on the system is as easy as (on Debian):
1/ updating the
/etc/locale.genfile, enabling the locales you wish to use, and2/ running the following command line:
(see
man locale-genfor instructions on your OS)At the end be aware that gettext php extension is per-process, so some OS/webserver configurations will rewrite the gettext settings of the parent webserver process. This will effectively switch this config for all the running threads. Imagine successfully setting the config in your script and start rendering the contents of your page in English, then another request comes and sets the French locale, and the rest of the execution your first request renders contents in French.
To avoid the situation described above (OS-specific changes to activate locales and per-process effect of gettext php extension), people develop gettext wrappers that use the
.pofiles to produce per-locale translations, store them as php scripts and call them by userland php code (instead of php_gettext extension).I wrote one of these some years ago, after several sleepless nights debugging the pure gettext php code, you can find link in my profile if interested.