【发布时间】:2016-06-13 12:23:32
【问题描述】:
我正在尝试使用 gettext 翻译我的 PHP 项目,但它不起作用。 PHP 输出 gettext 字符串名称而不是实际的翻译。 在 POeditor 中编译的 .po 文件。
设置语言环境:
// $language = 'en';
// $domain is the same as .mo file name
putenv("LANG=" . $language);
putenv("LANGUAGE=" . $language);
setlocale(LC_ALL, $language); // Also tried with .utf8 at the end
bindtextdomain($domain, 'locale'); // Also tried full path
textdomain($domain);
PO 文件:(在 locale/en/LC_MESSAGES/filename.po 中)
msgid "SETUP_UI"
msgstr "User Interface"
msgid "SETUP_ACCOUNT"
msgstr "Account and Login"
... and so on
在 PHP 中回显:
<?= gettext('SETUP_UI') ?>
是的,我尝试了 stackoverflow 中的所有内容 - 谷歌搜索超过 3 小时。我在 PHP 中安装了 gettext,还尝试重新启动 Apache,重新编译 .po 文件...
浏览器中的结果是:
SETUP_UI
感谢您的回答。
【问题讨论】:
标签: php apache translation gettext