【发布时间】:2012-05-16 05:49:39
【问题描述】:
我正在尝试使用 PHP gettext 扩展来翻译一些字符串。所有函数似乎都返回正确的值,但调用 gettext()/_() 仅返回原始字符串。 PO/MO 文件似乎是正确的,我相信我已经正确设置了目录。我在 Windows 上使用 PHP 5.3.10 运行 WAMP 服务器(也尝试运行 5.3.4 和 5.3.8,因为我有安装)。
首先,见/new2/www/index.php:
$locale = 'esn'; # returns Spanish_Spain.1252 in var dump
putenv("LC_ALL={$locale}"); // Returns TRUE
setlocale(LC_ALL, $locale); // Returns 'Spanish_Spain.1252'
$domain = 'messages';
bindtextdomain($domain, './locale'); // Returns C:\wamp\www\new2\www\locale
bind_textdomain_codeset($domain, 'UTF-8'); // Returns UTF-8
textdomain($domain); // Returns'messages'
print gettext("In the dashboard"); // Prints the original text, not the translation.
exit;
我创建了以下文件结构:
www/new2/www/locale/Spanish_Spain.1252/LC_MESSAGES/messages.mo
我还尝试将Spanish_Spain.1252 替换为:es_ES、esn、esp、Spanish 和 Spanish_Spain。
用于生成MO的PO文件是这样的(仅给出相关条目):
#: C:\wamp\www\new2/www/index.php:76
msgid "In the dashboard"
msgstr "TRANSLATED es_ES DASHBOARD"
这是使用 PoEdit 生成的。添加任何新的 .MO 文件后,我已重新启动 Apache。另请注意,我之前将 Zend_Translate 与 Gettext 一起使用,并且翻译正确。不过,我希望依赖本机 gettext 扩展,部分原因是我正在尝试创建自己的轻量级框架。
任何帮助将不胜感激。
编辑:修改目录结构。注意 - 将能够在 24 小时内尝试最近的答案。
【问题讨论】:
-
你的语言环境和目录不应该是
es_ES.UTF-8吗? -
@mario 我已经尝试过该语言环境和目录,但
setlocale()然后返回 false。
标签: php windows translation gettext poedit