小编Val*_*lla的帖子

PHP gettext 不起作用,如何调试?

我一直在尝试建立一个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 …

php gettext internationalization vagrant

5
推荐指数
1
解决办法
1493
查看次数

标签 统计

gettext ×1

internationalization ×1

php ×1

vagrant ×1