为什么 gettext 将空字符串转换为 .po 标头文本?
我已经在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在搜索了一些不同的查询后,我偶然发现了这个网站:
http://framework.zend.com/issues/browse/ZF-2914
这里我发现空字符串到元信息的翻译其实是在规范:
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:
您可以尝试创建另一个函数,仅当消息不同于空白或空字符串 ("") 时才调用 gettext。 php 中是这样的:
然后在 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:
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.