PHP gettext doesn't works

廉价感情. 提交于 2019-12-02 03:20:54

问题


Apache 2.4 + PHP 5.5

putenv('LC_ALL=ru_RU');
setlocale(LC_ALL, 'ru_RU');
bindtextdomain('mydomain', '/absolute/path/to/messages');
textdomain('mydomain');

I'm absolutely sure, than I've mydomain.po and mydomain.mo files in /absolute/path/to/messages/ru_RU/LC_MESSAGES/.
Also I gave these files to my colleague on OS X Maverics - worked fine.
I can't make php gettext working.

I've googled/stackoverflowed for about couple of hours, tried various solutions - still not working. What I do wrong?

I restart apache every time I change something to ensure gettext files is being reloaded.

Here is my locale -a output:

miraage@ubuntu:~$ locale -a
C
C.UTF-8
....
en_GB.utf8
....
POSIX
ru_RU.utf8
ru_UA.utf8

One more cmd output:

miraage@ubuntu:~$ sudo locale-gen ru
Generating locales...
  ru_RU.UTF-8... up-to-date
  ru_UA.UTF-8... up-to-date
Generation complete.

Okay, I've figured out:

sudo locale-gen ru_RU (added new locale, but different charset) and then setlocale(LC_ALL, 'ru_RU.UTF-8'); did all work.

Thanks for help.


回答1:


It is a long time asked question, but maybe one more check will help someone who will try everything "just by instruction" and still doesn't work.

That is collision with LANGUAGE environment variable.

In my case a while ago after a long fight, I figured out that it was causing the issue. Removing that environment variable export LANGUAGE= (empty, after =) resolved normal setLocale behavior.



来源:https://stackoverflow.com/questions/23652742/php-gettext-doesnt-works

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!