Gettext自动评论生成
我正在使用 gettext 为 php 项目执行 i18n 操作。我想使用自动注释功能在以下情况下向译者提供提示:翻译长短语时用 id 代替。我想要获得的是下面的po文件
#: full-path-to-file/index.phtml:3
#. a very long text which should replaced by _('foobar')
msgid "foobar"
msgstr ""
这样,当翻译者使用POEdit或程序员注释框中的一些模拟工具看到关键foobar
时,他就可以看到他应该翻译的内容。
我已经尝试使用此代码,但它不起作用
<?php
/// TRANSLATORS: a very long text which should replaced by _('foobar')
_('foobar');
?>
我是否遗漏了某些内容或自动注释不适用于 php?
即使 Wikipedia 提到此功能,我也尝试将其示例复制到 C 文件中,但我无法获取它我使用的命令行是
xgettext -C -o - main.c
但是生成的输出是
#: main.c:16
#, c-format
msgid "My name is %s.\n"
msgstr ""
所以我肯定错过了一些东西,我应该使用任何 xgettext
标志或特定版本来启用此功能。
I'm doing i18n for a php project using gettext. I'd like to use the automatic comment feature to give hints to translators when translating long phrases replaced by id. What I want to obtain is the following po file
#: full-path-to-file/index.phtml:3
#. a very long text which should replaced by _('foobar')
msgid "foobar"
msgstr ""
In this way the translator can see what he should translate when he see the key foobar
using POEdit or some analogue tool in the programmer comment box.
I've tried with this code but it doesn't work
<?php
/// TRANSLATORS: a very long text which should replaced by _('foobar')
_('foobar');
?>
Am I missing something or automatic comments just don't work for php?
Even Wikipedia mentions this feature, I've tried to copy their example in a C file, but I cannot get it working even with C. The command line I've used is
xgettext -C -o - main.c
But the generated output is
#: main.c:16
#, c-format
msgid "My name is %s.\n"
msgstr ""
So I'm definitely missing something, should I use any xgettext
flag or particular version to enable this feature.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要使 xgettext 从源中提取注释,您需要传递一个参数来告诉它要查找哪些注释。
来自文档:
传递
-c/
或--add-comments=/
作为参数将使其识别“三斜杠”格式。To make
xgettext
extract comments from your source, you need to pass an argument to tell it what comments to look for.From the documentation:
Passing
-c/
or--add-comments=/
as an argument will make it recognize the "triple slash" format.