gettext 设置不起作用
我的 gettext 可以工作,但现在它突然无法翻译了。我知道发生了什么事。我正在尝试使用 /sys/locale/no_NO/LC_MESSAGES/messages.po
将页面翻译为挪威语。
/public/home.php
$locale = "en_US";
if (isSet($_COOKIE['lang'])) $locale = $_COOKIE['lang'];
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", "../sys/locale");
textdomain("messages");
echo "<p>locale: " . $locale . " ";
echo gettext("Home");
exit();
这会打印出
locale: no_No Home
,而我应该是 locale: no_No Hjem
I had gettext working, but now it suddenly won't translate. I get find out whats going on. I am trying to use /sys/locale/no_NO/LC_MESSAGES/messages.po
to translate the page to norwegian.
/public/home.php
$locale = "en_US";
if (isSet($_COOKIE['lang'])) $locale = $_COOKIE['lang'];
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", "../sys/locale");
textdomain("messages");
echo "<p>locale: " . $locale . " ";
echo gettext("Home");
exit();
This prints out
locale: no_No Home
when I should be locale: no_No Hjem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我看到你在和挪威人打架。我也遇到了 Debian 服务器的问题,它只支持 nb_NO 和 nn_NO,但不支持 no_NO。
解决方案是使用区域设置名称的确切名称作为文件夹和设置:
确保安装了区域
设置:因此挪威语 bokmål 的 php 设置:
PO 文件的路径应具有相同的名称,例如:
我猜是相同的解决方案适用于 Ubuntu。
I see you are fighting with norwegian. I had the problem with Debian servers too which just support nb_NO and nn_NO but not no_NO.
The solution is to use the exact names of locale names as folder and setting:
Make sure you have the locales installed:
So the php setting for norwegian bokmål:
The path to the PO files should have the same name e.g.:
I guess the same solution will work for Ubuntu.
对于日语,我必须执行以下操作:
对于其他语言,我发现我并不总是需要添加编码后缀,这是非常不一致的。同样,当“en”工作正常时,我不能只使用“ja”。
setlocale
返回 false,除非区域设置在/usr/share/i18n/SUPPORTED
中列出,但尽管出现错误,翻译通常仍能正常工作。With Japanese I have to do the following:
With other languages I find I do not always have to add the encoding suffix, it is very inconsistent. Similarly I cannot just use "ja" when "en" works fine.
setlocale
returns false unless the locale is listed in/usr/share/i18n/SUPPORTED
but translations will often work despite the error.您可能需要重新配置语言环境:
安装 debconf (即以 root 身份运行 apt-get update 然后 apt-get install debconf)
以 root 身份运行 dpkg-reconfigure locales
此代码对我有用:
You might need to reconfigure locales:
Install debconf (I.e. Run apt-get update then apt-get install debconf, as root)
Run dpkg-reconfigure locales as root
This code worked for me: