在工作中,我们决定将我们的网站翻译成另外 3 种语言,我一直在研究如何做到这一点。我花了一天的大部分时间搜索谷歌和stackoverflow,尝试了每一种不同的解决方案,但我无法让它发挥作用。
我开始担心在 Windows 7 家庭版(我的开发机器)中无法做到这一点。
// C:\Apache24\htdocs\locale\en_GB\LC_MESSAGES\messages.mo
// C:\Apache24\htdocs\locale\en_GB\LC_MESSAGES\messages.po
msgid ""
msgstr ""
"Project-Id-Version: iArbete 1.0.0\n"
"Report-Msgid-Bugs-To: ******** \n"
"Last-Translator: ********\n"
"Language: en_GB\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "iArbete"
msgstr "workIng"
// C:\Apache24\htdocs\index.php
if(isset($_GET["locale"]))
{
$locale = $_GET["locale"];
}
else
{
$locale = 'en_GB';
}
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
echo getenv("LC_ALL");
$domain = 'messages';
bindtextdomain($domain, './locale');
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');
echo _("iArbete");
echo _("iArbete");
应该翻译成“workIng”,但事实并非如此。还是我没有得到这个概念?
- - 更多信息 - - - - - - - - - - - - - - - - - - - - - - - ------------
我做了一些更改并重新编译了 mo 文件,这就是它现在的样子。
// C:\Apache24\htdocs\locale\en_GB\LC_MESSAGES\messages.mo
// C:\Apache24\htdocs\locale\en_GB\LC_MESSAGES\messages.po
msgid ""
msgstr ""
"Project-Id-Version: iArbete 1.0.0\n"
"Report-Msgid-Bugs-To: ******** \n"
"Last-Translator: ********\n"
"Language: en_GB\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "workIng"
msgstr "iArbete"
msgid "Menu"
msgstr "Meny"
// C:\Apache24\htdocs\index.php
if(isset($_GET["locale"]))
{
$locale = $_GET["locale"];
}
else
{
$locale = 'sv_SE';
$locale = 'en_GB';
// $locale = 'ar_AE';
}
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
// echo getenv("LC_ALL");
$domain = 'messages';
bindtextdomain($domain, './locale');
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');
echo _("workIng");
echo _("Menu");
msgid "workIng"
被翻译成“iArbete”
msgid "Menu"
没有被翻译成“Meny”
到底是怎么回事?感觉很奇怪,只有第一个词被翻译。所以我重新排列了 po 中的单词并重新编译,但仍然“workIng”是唯一被翻译的单词?
如果有人想看看,我已经将我的文件上传到谷歌驱动器。