Gettext自动评论生成

发布于 2024-12-08 17:50:13 字数 924 浏览 5 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丑疤怪 2024-12-15 17:50:13

要使 xgettext 从源中提取注释,您需要传递一个参数来告诉它要查找哪些注释。

来自文档

'-c[标签]'
'--add-comments[=tag]'

放置注释块以
输出文件中的标记和前面的关键字行。如果没有标签,则
选项意味着将所有注释块放在关键字行之前
输出文件。

传递 -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:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文