I have been trying to set up a PHP website internationalization. No matter how much I try, I cannot get gettext to work.
I am running an ubuntu apache server on a vagrant box, all locales I need are both available and generated (used locales -a to check).
Gettext is installed and enabled (checked with phpinfo())
This is my PHP:
$locale = 'en_US'
putenv('LANGUAGE=' . $locale); //found it somewhere, doesn't make a difference though
putenv('LC_ALL=' . $locale);
echo setlocale(LC_ALL, $locale); //seems to work fine
echo bindtextdomain($locale, "/vagrant/build/locale"); //folder exists and corresponds with return string
textdomain($locale);
echo gettext("Not working!");
This is my /vagrant/build/locale/en_US/LC_MESSAGES/en_US.po file:
msgid ""
msgstr ""
"Language: en_US\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "Not working!"
msgstr "ITS WORKIN OMFG!"
Everything seems to check out, except the translation just does not work.
I tried adding .utf-8 (and variations such as .UTF-8 and .utf8) to the locale in putenv(), setlocale() and the folder name, but nothing changed.
How does one debug this kind of stuff? Outputting variables only took me so far, as everything seems to be working.
Is there something I'm missing here? I wasted so much time on this issue, I just wish I had gone with associative arrays instead.