我一直在尝试建立一个PHP网站的国际化。无论我尝试多少,我都无法让 gettext 工作。
我在流浪盒上运行 ubuntu apache 服务器,我需要的所有语言环境都可用并生成(使用 locales -a 检查)。
Gettext 已安装并启用(使用 phpinfo() 检查)
这是我的PHP:
$locale = 'en_US'
putenv('LANGUAGE=' . $locale); //found it somewhere, doesn't make a difference though
putenv('LC_ALL=' . $locale);
echo setlocale(LC_ALL, $locale); //seems to work fine
echo bindtextdomain($locale, "/vagrant/build/locale"); //folder exists and corresponds with return string
textdomain($locale);
echo gettext("Not working!");
Run Code Online (Sandbox Code Playgroud)
这是我的 /vagrant/build/locale/en_US/LC_MESSAGES/en_US.po 文件:
msgid ""
msgstr ""
"Language: en_US\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "Not working!"
msgstr "ITS WORKIN OMFG!"
Run Code Online (Sandbox Code Playgroud)
一切似乎都检查出来了,除了翻译不起作用。
我尝试将 .utf-8(以及 .UTF-8 …