我在 Windows 上使用 WAMP 服务器并制作了一个测试项目。我在网站文件夹中有这些文件:
C:\wamp\www\project\locale\ar_EG\LC_MESSAGES\messages.po C:\wamp\www\project\locale\en_US\LC_MESSAGES\messages.po
下面是PHP代码:
$language="en_US";
$encoding = "UTF-8";
putenv("LANG=".$language);
setlocale(LC_ALL,$language);
$domain="messages"; // name of PO file
bindtextdomain($domain,"Locale");
bind_textdomain_codeset($domain, $encoding);
textdomain($domain);
echo gettext("name");
上面的代码工作正常。当我尝试en_US
用ar_EG
它替换时,也会显示翻译en_US
,当我尝试删除en_US
文件夹并重试时,它会显示msgid
not msgstr
。
我搜索了一下,发现是setlocale
在windows平台上有问题,但是我需要一个解决方案让它在windows上运行。