I'm using gettext
for internationalization for my php files. I have two servers; a sandbox server and a release server. in sandbox server a directory like locale/LC_MESSAGES/en
does not work and I should use locale/LC_MESSAGES/en_GB
instead. But with "en_GB" it doesn't work on my production server and "en" works fine. for some languages like Portuguese I have pt_PT and pt_BR (Brazilian Portuguese). So I prefer to use the "A_B" structure.
I have no idea how gettext
detects these folders. Is there a standard way to use the same folder structure?
If you're running your code on Linux,
gettext
works only with locales already installed on the OS. This means that if you set the locale toen_GB
then if the only installed locale isen_GB.utf8
oren_US
, then you don't get the translations.Try this on both of your environments and compare the results:
It gives you a list of all the installed locales:
Now you need to make sure that both of the environments have the same locales installed; If you need
en_US.utf8
,en_AU
, anden_AU.utf8
, you can create the missing locales based on an existing one (readlocaledef
manpages to know the details):Also, what follows is the common best practice for using
gettext
on PHP:Although you can simply drop the encoding and just
de_DE
, but it's a good practice to have the character set in the locale as in some specific cases you might need to support content in non-Unicode character sets. See below