开发者

Gettext automatic comments generation

开发者 https://www.devze.com 2023-04-10 17:40 出处:网络
I\'m doing i18n for a php project using gettext. I\'d like to use the automatic comment feature to give hints to translator开发者_如何学运维s when translating long phrases replaced by id. What I want

I'm doing i18n for a php project using gettext. I'd like to use the automatic comment feature to give hints to translator开发者_如何学运维s 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号