PHP gettext不';t工作
Apache2.4+PHP5.5PHP gettext不';t工作,php,gettext,php-gettext,Php,Gettext,Php Gettext,Apache2.4+PHP5.5 putenv('LC_ALL=ru_RU'); setlocale(LC_ALL, 'ru_RU'); bindtextdomain('mydomain', '/absolute/path/to/messages'); textdomain('mydomain'); 我绝对肯定,我在/absolute/path/to/messages/ru\ru/LC\u messages/中有mydomain.po和mydomain.mo文件 我还将这些文件交给了我在OS
putenv('LC_ALL=ru_RU');
setlocale(LC_ALL, 'ru_RU');
bindtextdomain('mydomain', '/absolute/path/to/messages');
textdomain('mydomain');
我绝对肯定,我在/absolute/path/to/messages/ru\ru/LC\u messages/
中有mydomain.po
和mydomain.mo
文件
我还将这些文件交给了我在OS X Maverics上的同事,效果很好。我无法使php gettext正常工作 我在Google/StackOverflow上搜索了大约两个小时,尝试了各种解决方案——仍然不起作用。我做错了什么? 每次更改某些内容以确保重新加载gettext文件时,我都会重新启动apache 这是我的
locale-a
输出:
miraage@ubuntu:~$ locale -a
C
C.UTF-8
....
en_GB.utf8
....
POSIX
ru_RU.utf8
ru_UA.utf8
还有一个cmd输出:
miraage@ubuntu:~$ sudo locale-gen ru
Generating locales...
ru_RU.UTF-8... up-to-date
ru_UA.UTF-8... up-to-date
Generation complete.
好吧,我想起来了:
sudo区域设置gen ru_ru
(添加了新的区域设置,但不同的字符集)
和
然后setlocale(LC_ALL,'ru_ru.UTF-8')代码>完成了所有工作
谢谢你的帮助。这是一个很长时间的问题,但也许再多检查一次会帮助那些“仅凭指导”尝试一切但仍然不起作用的人
这与语言
环境变量冲突
在我的案例中,经过长时间的斗争,我发现这是问题的根源。删除环境变量export LANGUAGE=
(在=
之后为空)解决了正常的setLocale
行为。它究竟是如何工作的?你们总是有相同的目录吗?你根本就没有目录?和错误信息?setlocale()
和textdomain()
返回什么?setlocale()
返回了false
,textdomain()
返回了mydomain。谢谢你的评论。将尝试找出区域设置。我使用了putenv('LANG=ru_-ru')代码>-不知道您在那里设置了LC\u ALL
?您可能需要setlocale(…,'ru\u ru.utf8')
ru_-ru
不在locale-a
的输出中。已尝试ru
,ru-ru
,ru.utf8
。仍然没有结果。