gettext 在本地工作,但不在主机服务器上
我在 PHP 应用程序中遇到了 gettext
的奇怪问题。它可以在我的开发机器上运行(Ubuntu 10.10 32 位、2 个 Windows 7 64 位、Windows 7 32 位,全部运行 XAMPP)。
生产服务器是运行某种Linux 64 位的付费主机。我不知道到底是哪一个。我可以尝试看看这是否重要。
以下是我初始化 gettext 的方法:
//just FYI:
//$this->data['language'] == 'pl'
//dirname(__FILE__).'/../language/locale' ==
//'/home/mingos/public_html/example.com/application/controllers/../language/locale'
putenv('LANGUAGE='.$this->data['language']);
putenv('LANG='.$this->data['language']);
putenv('LC_ALL='.$this->data['language']);
setlocale(LC_ALL,$this->data['language']);
bindtextdomain($this->data['language'], dirname(__FILE__).'/../language/locale');
bind_textdomain_codeset($this->data['language'],'UTF-8');
textdomain($this->data['language']);
我在服务器上运行 phpinfo()
并发现 gettext
已启用并且 safe_mode 已关闭,排除了
LC_ALL
不可修改的可能性(我认为)。
编译后的gettext目录为:
/home/mingos/public_html/example.com/application/language/locale/pl/LC_MESSAGES/pl.mo
所以bindtextdomain
中设置的路径是正确的。
我没有收到任何通知或警告,但 gettext
不会从我的目录中提取翻译,仅返回所输入的字符串,例如 gettext('About us')
返回关于我们
而不是O nas
。
目录本身使用 poEdit
正确编译,并确认可以在我的 4 台开发机器上运行。
造成这种情况的其他可能原因是什么?
I'm facing an odd issue with gettext
in my PHP application. It works on my development machines (Ubuntu 10.10 32 bit, 2 x Windows 7 64 bit, Windows 7 32 bit, all running XAMPP).
The production server is a paid host running some flavour of Linux 64 bit. I don't know exactly which. I can try to find out if it matters.
Here is how I initialise gettext:
//just FYI:
//$this->data['language'] == 'pl'
//dirname(__FILE__).'/../language/locale' ==
//'/home/mingos/public_html/example.com/application/controllers/../language/locale'
putenv('LANGUAGE='.$this->data['language']);
putenv('LANG='.$this->data['language']);
putenv('LC_ALL='.$this->data['language']);
setlocale(LC_ALL,$this->data['language']);
bindtextdomain($this->data['language'], dirname(__FILE__).'/../language/locale');
bind_textdomain_codeset($this->data['language'],'UTF-8');
textdomain($this->data['language']);
I ran phpinfo()
on the server and found out that gettext
is enabled and safe_mode
is off, excluding the possibility LC_ALL
being unmodifiable (I think).
The compiled gettext catalog is:
/home/mingos/public_html/example.com/application/language/locale/pl/LC_MESSAGES/pl.mo
So the path set in bindtextdomain
is correct.
I do not get any notices or warnings, but gettext
does not extract translations from my the catalog, returning simply the strings it is fed, e.g. gettext('About us')
returns About us
instead of O nas
.
The catalog itself is compiled correctly using poEdit
and is confirmed to be working on my 4 dev machines.
What might be the other possible causes of this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
gettext 将仅支持已安装的区域设置。如果您的托管提供商有 shell,您应该运行“locale -a”来查看已安装区域设置的列表。您可能需要联系您的托管提供商,让他们安装 pl 所需的语言包。
gettext will only support the installed locales. If you have a shell on your hosting provider you should run 'locale -a' to see a list of installed locales. You may need to contact your hosting provider to have them install the necessary language pack for pl.
这是一个老问题,但我想解释一下为什么它在 Windows 上运行而不是在 Linux 上运行。 Windows 服务器不使用与 Linux 服务器相同的区域设置名称。例如,在 Windows 中,您将拥有“en”,但在 Linux 上,您将拥有“en_EN”。与波兰语相同,在 Windows 上它将是“pl”,在 Linux 上它将是“pl_PL”。您需要对本地或实时服务器进行某种类型的测试,并相应地更改区域设置字符串。
An old question, but I wanted to explain why it worked on Windows and not on Linux. Windows servers don't use the same locale names as Linux servers. For example, in Windows you will have "en", but on Linux you'll have "en_EN". It's the same with Polish, on Windows it will be "pl" and on Linux it will be "pl_PL". You'll need to have some type of test for your local or live server and change the locale string accordingly.