我正在尝试在 php 5.5 中使用 php gettext 扩展名(在 win2008 服务器上,使用 IIS7)。我正在这样做:
<?php
$locale = "es";
if (isSet($_GET["locale"])) $locale = $_GET["locale"];
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", "./locale");
textdomain("messages");
echo gettext("Hello world");
?>
有了这个文件夹结构:
locale/es/LC_MESSAGES/messages.mo
但它总是只返回 Hello world 而不是正确的翻译,目前(基于我缺乏西班牙语技能)在 messages.po 文件中是这样的:
msgid ""
msgstr ""
"Project-Id-Version: TestXlations\n"
"POT-Creation-Date: 2014-04-19 08:15-0500\n"
"PO-Revision-Date: 2014-04-19 09:18-0500\n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.6.3\n"
"X-Poedit-Basepath: .\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-SearchPath-0: c:/dev\n"
msgid "Hello world"
msgstr "Hola World"
这从 cmd 行和通过 IIS 失败。所以我看到 gettext 调用等并执行它,但它没有读取翻译文件。我该如何进一步调试?即使删除翻译文件,我也会得到相同的行为。