Gettext自动生成注释 [英] Gettext automatic comments generation

查看:231
本文介绍了Gettext自动生成注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用gettext为一个php项目做i18n。我想使用自动评论功能向翻译者提供提示翻译由短语替换的长短语。我想获得的是以下po文件

 #:full-path-to-file / index.phtml:3 
#。一个很长的文本应该替换为_('foobar')
msgidfoobar
msgstr

这样,当他在程序员注释框中使用POEdit或一些模拟工具看到键 foobar 时,翻译人员可以看到他应该翻译什么。



我尝试过此代码,但无效

 <?php 
/// TRANSLATORS:一个很长的文本,应该替换为_('foobar')
_('foobar');
?>

我缺少某些内容或自动注释不适用于php?



即使维基百科提及此功能,我已尝试复制其示例一个C文件,但我不能得到它工作即使与C.我使用的命令行是

  xgettext -C  - o  -  main.c 

但生成的输出是

 #:main.c:16 
#,c-format
msgid我的名字是%s.\\\

msgstr

所以我绝对缺少一些东西,应该使用任何 xgettext $

xgettext



http://www.gnu.org/software/gettext/manual/gettext.html#index-g_t_002d_002dadd_002dcomments_0040r_007b_002c-_0040code_007bxgettext_007d-option_007d-183\">文档



< blockquote>

' -c [tag] '

' - add-comments [=标签] '



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


-c / - add-comments = / 作为参数传递将使其识别 格式。


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.

解决方案

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.

这篇关于Gettext自动生成注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆