PHP gettext不起作用 [英] PHP gettext doesn't works

查看:134
本文介绍了PHP gettext不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apache 2.4 + PHP 5.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_MESSAGES/中的mydomain.pomydomain.mo文件.
我还把这些文件交给了我在OS X Maverics上的同事-工作正常.
我无法使php gettext工作.

我已经搜索/堆栈溢出了大约两个小时,尝试了各种解决方案-仍然无法正常工作.我做错了什么?

每次更改内容以确保重新加载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 locale-gen ru_RU(添加了新的语言环境,但字符集不同) 和 然后setlocale(LC_ALL, 'ru_RU.UTF-8');完成了所有工作.

感谢您的帮助.

解决方案

这是一个很久以来问过的问题,但是也许再检查一次将有助于某人仅凭指示"尝试一切,但仍然行不通. /p>

那是与LANGUAGE环境变量的冲突.

就我的情况而言,经过长时间的奋斗,我发现是造成此问题的原因.删除该环境变量export LANGUAGE=(在=之后为空)可以解决setLocale的正常行为.

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.

解决方案

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.

这篇关于PHP gettext不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆