使用gettext php函数无法翻译成任何其他语言 [英] can't translate to any other language using gettext php function
问题描述
对于谁具有本地化和gettext功能的经验
我在Windows上使用WAMP服务器并制作测试项目。我在网站文件夹中有这些文件:
For who have experience with localization and gettext function
I use a WAMP server on Windows and make a test project. I have these files in the website folder:
C:\wamp\www\project\locale\ar_EG\LC_MESSAGES\messages.po C:\wamp\www\project\locale\en_US\LC_MESSAGES\messages.po
以下是PHP代码:
Below is the PHP Code:
$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");
以上代码工作正常。当我尝试用 ar_EG 替换 en_US 时,它还会显示 en_US 的翻译,当我尝试删除 en_US 文件夹然后重试它会显示 msgid 而不是 msgstr 。
我搜索并发现有Windows平台上的 setlocale 功能存在问题,但我需要一个解决方案才能在Windows上运行,任何想法?
Above code is working fine. When I try to replace en_US with ar_EG it also displays the translation for en_US, and when I try to remove the en_US folder and try again it displays the msgid not msgstr.
I searched and found that there is a problem with setlocale function on the Windows platform, but I need a solution for it to run on Windows , any idea ?
推荐答案
语言= en_US;
language="en_US";
encoding = UTF-8\" 跨度>;
putenv( LANG =。
encoding = "UTF-8"; putenv("LANG=".
语言);
setlocale(LC_ALL,
language); setlocale(LC_ALL,
这篇关于使用gettext php函数无法翻译成任何其他语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!