Php gettext 不显示翻译后的文本(使用 poEdit 生成 .pot 和 .mo 文件后)
我遵循了以下教程: http ://mel.melaxis.com/devblog/2005/08/06/localizing-php-web-sites-using-gettext/
关于 Php gettext 扩展(我未选中 php.ini 中的注释
)已激活,但不显示翻译(德语)。
以下是文件:
C:\wamp\www\php-test\test.php:
<?php
require_once("localization.php");
echo _("Hello World!");
?>
C:\wamp\www\php-test\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:\ wamp \ www \ php-test \ locale \ 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 <[email protected]>\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:\ wamp \ www \ php-test \ locale \ de_DE \ LC_MESSAGES \ messages.mo
(抱歉,由于某种原因,我无法复制此文件的文本)
当我打开它时,它应该显示“Hallo Welt”(德语的 Hello World),但它却以英语显示(你好世界)。
有什么建议吗?
PS:我使用的是Windows XP SP2
I followed the folling tutorial: http://mel.melaxis.com/devblog/2005/08/06/localizing-php-web-sites-using-gettext/
about Php gettext extension (I unchecked the comment in the php.ini)
The gettext is activated but it doesn't show up the translation (German).
Here are the files:
C:\wamp\www\php-test\test.php:
<?php
require_once("localization.php");
echo _("Hello World!");
?>
C:\wamp\www\php-test\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:\wamp\www\php-test\locale\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 <[email protected]>\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:\wamp\www\php-test\locale\de_DE\LC_MESSAGES\messages.mo
(sorry from some reason I can't copy the text of this file)
When I open it should display "Hallo Welt" (Hello World in German) but instead it displays it in English (Hello World).
Any suggestions?
PS: I'm using Windows XP SP2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我之前使用的是 Wamp Server 2 (i),我卸载了它并使用了 Wamp Server 2 (c),它解决了问题。诡异的。
I was using Wamp Server 2 (i), I uninstalled it and used Wamp Server 2 (c), and it fixed the problem. Weird.
正如 setlocale 手册页中所述(您是否读过吗?),Windows 使用不同的语言/国家/地区 字符串。尝试将它们添加到您的
de_DE
中,如下所示(也可从手册页中 ):另请参阅有关每个进程维护的区域设置信息的警告。
as stated in the manual page for
setlocale
(did you read it?), windows uses different language/country/region strings. try adding them to yourde_DE
, like so (also from the man page):see also the warning on locale information being maintained per process.
我知道有点基础,但是你尝试过重新启动网络服务器吗?每次更新
.mo
文件时我都必须这样做。A bit basic, I know, but did you try to restart the web server? I have to do it everytime I update my
.mo
files.为消息目录提供的目录路径(bindtextdomain 函数的第二个参数)应包含 de_DE/LC_MESSAGES/ ,在此目录中您必须复制 mo 文件。
Directory path provided for message catalog (second parameter of bindtextdomain function) should contain de_DE/LC_MESSAGES/ in this directory you have to copy your mo file.
您所需要做的就是重新启动 Apache。
All you need to do was restart Apache.