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

发布于 2024-08-21 11:03:44 字数 2005 浏览 8 评论 0原文

我遵循了以下教程: 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

(抱歉,由于某种原因,我无法复制此文件的文本)

alt text

当我打开它时,它应该显示“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)

alt text

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

薄荷→糖丶微凉 2024-08-28 11:03:44

我之前使用的是 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.

少女的英雄梦 2024-08-28 11:03:44

正如 setlocale 手册页中所述(您是否读过吗?),Windows 使用不同的语言/国家/地区 字符串。尝试将它们添加到您的 de_DE 中,如下所示(也可从手册页中 ):

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

另请参阅有关每个进程维护的区域设置信息的警告。

as stated in the manual page for setlocale (did you read it?), windows uses different language/country/region strings. try adding them to your de_DE, like so (also from the man page):

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

see also the warning on locale information being maintained per process.

埋情葬爱 2024-08-28 11:03:44

我知道有点基础,但是你尝试过重新启动网络服务器吗?每次更新 .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.

太傻旳人生 2024-08-28 11:03:44

为消息目录提供的目录路径(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.

审判长 2024-08-28 11:03:44

您所需要做的就是重新启动 Apache。

All you need to do was restart Apache.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文