Gettext automatic comments generation

浪尽此生 提交于 2019-12-20 19:42:19

问题


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.


回答1:


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:

-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.

Passing -c/ or --add-comments=/ as an argument will make it recognize the "triple slash" format.



来源:https://stackoverflow.com/questions/7665274/gettext-automatic-comments-generation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!