为什么 gettext 将空字符串转换为 .po 标头文本?

发布于 2024-12-07 09:53:52 字数 786 浏览 1 评论 0原文

我已经在 PHP5 中设置了 gettext。经过一番与字符集等的斗争之后,我成功地翻译了一些基本的字符串。现在我遇到了一个问题。当翻译一个空字符串时,我希望得到未翻译的(空)字符串(如果我错了,请纠正我;))。

但是,我没有返回输入字符串,而是将 .PO 文件的标头作为翻译:

Project-Id-Version: PACKAGE VERSION Report-Msgid-Bugs-To: POT-Creation-Date: 2011-09-22 15:03+0200 PO-Revision-Date: 2011-09-22 15:37+0200 Last-Translator: timo Language-Team: English Language: en MIME-Version: 1.0 Content-Type: text/plain; charset=ASCII Content-Transfer-Encoding: 8bit Plural-Forms: nplurals=2; plural=(n != 1); 

当我使用文本编辑器查看 .mo 文件时,我发现标头似乎放置在文件内的随机位置。我想向您展示,但我无法粘贴该文件。看起来有一个我的 msgid 列表,然后是标题,然后是我的 msgstr 列表

我使用以下命令生成 .mo文件:

msgfmt -c -v -o en/LC_MESSAGES/messages.mo messages_en.po

执行此命令后,我重新启动了我的网络服务器(lighttpd)。

我做错了什么以及如何解决?

I've got gettext setup within PHP5. After some struggling with the charactersets and the like, I've managed to translate some basic strings. Now I've ran into a problem. When translating an empty string I expect to get the untranslated (empty) string back (correct me if I'm wrong ;)).

However instead of returning the input string, I get the header of the .PO file as the translation:

Project-Id-Version: PACKAGE VERSION Report-Msgid-Bugs-To: POT-Creation-Date: 2011-09-22 15:03+0200 PO-Revision-Date: 2011-09-22 15:37+0200 Last-Translator: timo Language-Team: English Language: en MIME-Version: 1.0 Content-Type: text/plain; charset=ASCII Content-Transfer-Encoding: 8bit Plural-Forms: nplurals=2; plural=(n != 1); 

When I look in the .mo file with a text-editor I see that the header seems to placed at a random place within the file. I would like to show you, but I can't paste the file in. It looks like there is a list of my msgid's, then the header and then a list of my msgstr's

I've used the following command to generate the .mo file:

msgfmt -c -v -o en/LC_MESSAGES/messages.mo messages_en.po

After this command I've restarted my webserver (lighttpd).

What did I do wrong and how can I fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

顾忌 2024-12-14 09:53:52

在搜索了一些不同的查询后,我偶然发现了这个网站:
http://framework.zend.com/issues/browse/ZF-2914

这里我发现空字符串到元信息的翻译其实是在规范

这还有另一个优点,因为 PO 文件中的空字符串 GNU gettext 通常被翻译为附加到该特定 MO​​ 文件的一些系统信息,并且空字符串必然成为原始表和翻译表中的第一个,从而使得系统信息很容易找到。

After searching around with some different queries I stumbled upon this site:
http://framework.zend.com/issues/browse/ZF-2914

Here I found that the translation of the empty string to meta information is actually in the specifications of gettext:

This also has another advantage, as the empty string in a PO file GNU gettext is usually translated into some system information attached to that particular MO file, and the empty string necessarily becomes the first in both the original and translated tables, making the system information very easy to find.

红颜悴 2024-12-14 09:53:52

您可以尝试创建另一个函数,仅当消息不同于空白或空字符串 ("") 时才调用 gettext。 php 中是这样的:

function _tl($msg)
{
    $ret = "";
    if($msg != "")
    {
        $ret = _($msg);
    }    

    return $ret;

}

然后在 poedit 上,在目录首选项上,在关键字选项卡上设置新函数 _tl 的使用。这就是 poedit 在您的代码中识别它的方式。

You can try creating another function to call gettext only when the message it is different from blank or empty string (""). Something like this in php:

function _tl($msg)
{
    $ret = "";
    if($msg != "")
    {
        $ret = _($msg);
    }    

    return $ret;

}

Then on poedit, on your catalog preferences, on the keywords tab set the using of the new function _tl. This is the manner which poedit will recognize it on your code.

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