开发者

PHP: Gettext problems

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?


It seems as though the problem may be with poedit. Originally, all my Spanish translations I had marked as "fuzzy". If I remove "fuzzy" from them, they show up on my webpage like they should.

I don't think this is normal behavoir, but hey, at least it works.


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. =)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜