我正在使用 gettext 为一个 php 项目做国际化。我想使用 automatic comment feature在翻译由 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 不起作用?
甚至维基百科 mentions此功能,我试图将他们的示例复制到 C 文件中,但即使使用 C 也无法使其工作。我使用的命令行是
xgettext -C -o - main.c
但是生成的输出是
#: main.c:16
#, c-format
msgid "My name is %s.\n"
msgstr ""
所以我肯定遗漏了一些东西,我应该使用任何 xgettext
标志或特定版本来启用此功能。
最佳答案
要使 xgettext
从您的源代码中提取注释,您需要传递一个参数来告诉它要查找哪些注释。
来自documentation :
‘
-c[tag]
’
‘--add-comments[=tag]
’Place comment blocks starting with tag and preceding keyword lines in the output file. Without a tag, the option means to put all comment blocks preceding keyword lines in the output file.
传递 -c/
或 --add-comments=/
作为参数将使其识别“三斜杠”格式。
关于php - Gettext自动注释生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7665274/