Php gettext没有显示翻译的文本(使用poEdit生成.pot和.mo文件之后)!

时间:2010-02-14 15:32:21

标签: php gettext poedit

我遵循了以下教程:http://mel.melaxis.com/devblog/2005/08/06/localizing-php-web-sites-using-gettext/

关于Php gettext扩展(我取消选中php.ini中的注释)

gettext已激活,但未显示翻译(德语)。

以下是文件:

C:\瓦帕\ WWW \ PHP-测试\ test.php的:

<?php
require_once("localization.php");
echo _("Hello World!");
?>

C:\瓦帕\ WWW \ PHP-测试\ localization.php:

<?php
$locale = "de_DE";
if (isSet($_GET["locale"])) $locale = $_GET["locale"];
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", "./locale");
textdomain("messages");
?>

C:\瓦帕\ WWW \ PHP-测试\区域\ de_DE这个\ LC_MESSAGES \ messages.po:

msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-02-14 00:35+0800\n"
"PO-Revision-Date: 2010-02-14 00:37+0800\n"
"Last-Translator: Jano Chen <weedcl@hotmail.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-KeywordsList: _;gettext;gettext_noop\n"
"X-Poedit-Basepath: C:\\wamp\\www\\php-test\n"
"X-Poedit-Language: German\n"
"X-Poedit-Country: GERMANY\n"
"X-Poedit-SourceCharset: iso-8859-1\n"
"X-Poedit-SearchPath-0: .\n"

#: test.php:2
msgid "Hello World!"
msgstr "Hallo Welt!"

C:\瓦帕\ WWW \ PHP-测试\区域\ de_DE这个\ LC_MESSAGES \ messages.mo

(遗憾的是我无法复制此文件的文本)

alt text http://img202.imageshack.us/img202/8892/mofile.png

当我打开它时,应显示“Hallo Welt”(德语中的Hello World),但它会以英语显示(Hello World)。

有什么建议吗?

PS:我正在使用Windows XP SP2

5 个答案:

答案 0 :(得分:1)

我正在使用Wamp Server 2(i),我卸载了它并使用了Wamp Server 2(c),它解决了这个问题。怪异。

答案 1 :(得分:0)

setlocale的手册页中为stated(你读过吗?),windows使用不同的language / country/region字符串。尝试将它们添加到de_DE,就像这样(from the man page):

setlocale(LC_ALL, 'de_DE', 'deu_deu');

另请参阅每个进程维护的语言环境信息警告。

答案 2 :(得分:0)

有点基本,我知道,但你是否尝试重新启动网络服务器?我每次更新.mo文件时都必须这样做。

答案 3 :(得分:0)

为消息目录提供的目录路径(bindtextdomain函数的第二个参数)应包含de_DE / LC_MESSAGES /,在此目录中您必须复制mo文件。

答案 4 :(得分:0)

您需要做的就是重启Apache。