Page 1 of 1

gettext: Messages not translated. No error message.

Posted: Tue Dec 06, 2016 6:09 pm
by ^rooker
[PROBLEM]
Using gettext/poedit to make a PHP project translatable.
I have a working test-code from PHP and Javascript Internationalization using Gettext and Poedit (pontikis.net). When I move that working code to another machine, I suddenly don't get strings displayed translated, but also no error messages.

[SOLUTION]
The target locale was not installed on system.
Even if you provide the translation files, PHP will not switch to a locale which is not installed/configured on the system that your application is running.

In my case, PHP's setlocale() returned 'false' - indicating that I my target locale was missing.
Check if the locale is currently present and active:

Code: Select all

$ locale -a
If not, either uncomment them in "/etc/locale.gen" and then (re-)generate them:

Code: Select all

$ sudo locale-gen
Or rather do it the "Official Debian Way":

Code: Select all

$ sudo dpkg-reconfigure locales
There, make sure that all the languages/locales you're going to use are checked/selected. After pressing "Ok", they will automatically be (re-)generated.

This should do the trick :D