PHP Gettext – 没有翻译
我试图使用
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:wampwwwnew2wwwlocale 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:wampwwwnew2/www/index.php:76 msgid "In the dashboard" msgstr "TRANSLATED es_ES DASHBOARD" 这是使用PoEdit生成的.添加任何新的.MO文件后,我重新启动了Apache.另请注意,我之前使用Zend_Translate和Gettext,它正在正确翻译.我希望依赖本机gettext扩展,部分原因是我试图创建一个自己的轻量级框架. 任何帮助,将不胜感激. 编辑:修改后的目录结构.注意 – 将能够在24小时内尝试最近的答案.
我在我的XAMPP实例上进行了设置并弄明白了.
>扁平化setlocale在Windows上不起作用,因此返回的内容无关紧要. $locale = 'es_ES'; putenv("LC_ALL={$locale}"); // Returns TRUE $domain = 'messages'; bindtextdomain($domain,'./locale'); bind_textdomain_codeset($domain,'UTF-8'); textdomain($domain); // Returns'messages' print gettext("In the dashboard"); exit; 我不确定这是否有所不同,但我在创建po文件时做了两件事.在文件中的poEdit – >首选项我将行结束格式更改为Windows.在用poEdit创建初始po后,我在记事本中打开文件,并将编码类型切换为UTF-8,因为poEdit没有这样做. 我希望这至少能指出你正确的方向. 参考 PHP Localization Tutorial on Windows Country Codes Language Codes (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |