So this mystery resolved by excellent SOQ
One of the comment for gettext on php.net says:
Warning for Linux (Ubuntu) users! Your system will *only* support the locales installed on your OS, in the *exact* format given by your OS. (See also the PHP setlocale man page.) To get a list of them, enter locale -a, which will give you something like this:
C
en_US.utf8
ja_JP.utf8
POSIX
So this machine only has English and Japanese! To add eg. Finnish, install the package:
sudo apt-get install language-pack-fi-base
Rerun locale -a, and "fi_FI.utf8" should appear. Make sure you're using the same name in your PHP code:
setlocale(LC_ALL, "fi_FI.utf8");
Adjust your po paths so that they match, e.g. "./locale/fi_FI.utf8/LC_MESSAGES/messages.po".
Now restart Apache, and it should finally work. Figuring this out took quite a while...
My issue resolved exactly by following these steps:
- sudo apt-get install language-pack-da-base (danish)
- locale -a (confirmed da_DK locale loaded)
mv da_DK da_DK.utf8 (renamed the locales dir)bind_textdomain_codeset('messages', 'UTF8');
One of the debugging point for me was
setlocale(LC_ALL, 'da_DK.utf8');
which was returning false for invalid/non-existent locales
What about gettext.so extension:
The php installation I got through apt-get seems to have the extension added during compilation
We can see if gettext is compiled module e.g php -m |grep gettext
, which seems to be true !
I don't need gettext.ini, which is desired only when PHP is compiled --with-gettext=shared
, which is not the case here.