PHP: Gettext problems

gettextlocalePHP

I can't seem to get gettext working, here.

I'm using MAMP Pro and phpinfo(); says that gettext is enabled.

I followed this tutorial: http://zez.org/article/articleview/42/1/

  1. I have my strings declared in my code like this: _('test string');
  2. Then I ran xgettest -L PHP test.php, which generated my messages.po file.
  3. I opened this file in poedit and translated my strings, then saved the file, which made a messages.mo file.
  4. I took both the .po and .mo files and moved them to [webroot]/locale/es/LC_MESSAGES/ (in this case, my translation was Spanish)
  5. In my code, I set the following:

    $lang = $_SESSION['lang']; // available to all views that include this file

    putenv('LC_ALL='.$lang);

    bindtextdomain('messages','./locale');

    textdomain('messages');

    … where $_SESSION['lang'] I can easily toggle between en and es.

  6. I reload my page, then click on my link that toggles to es, but my strings are still showing up as the English versions and not the Spanish versions. Toggling back to en shows no change; it's always the English versions.

I get no error message anywhere so I'm a bit lost as to why I'm having this problem. Can anyone give me some guidance/help? Did I miss something?

Best Answer

You also need to install the corresponding language files on your server as so:

cat /usr/share/i18n/SUPPORTED |grep -i "es_ES" > /var/lib/locales/supported.d/es
cat /usr/share/i18n/SUPPORTED |grep -i "nl_NL" > /var/lib/locales/supported.d/nl
cat /usr/share/i18n/SUPPORTED |grep -i "de_DE" > /var/lib/locales/supported.d/de

Now you installed the languages Spanish, Dutch and German. When finished, run dpkg-reconfigure locales and you are done. =)