使用JavaScript中的xgettext提取翻译者注释(在Python模式下) [英] Extract translator comments with xgettext from JavaScript (in Python mode)

查看:243
本文介绍了使用JavaScript中的xgettext提取翻译者注释(在Python模式下)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常好用的命令,可以从我所有的.js和.html文件中提取字符串(这些文件只是Underscore模板)。但是,它似乎不适用于译者评论。

I have a pretty well-working command that extracts strings from all my .js and .html files (which are just Underscore templates). However, it doesn't seem to work for Translator comments.

例如,我在我的一个.js文件中有这个:

For example, I have this in one of my .js files:

/// TRANSLATORS: The word "manual" stands for manual process
gettext("manual");

使用以下命令:

find . -iname '*.html' -o -iname '*.js' | xargs xgettext --language=Python --from-code=utf-8 --keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 --add-comments=/ 

xgettext应该从.js文件中提取注释并将其放入我的.po文件中,如下所示:

xgettext should extract the comment from the .js file and put it into my .po file like this:

#. TRANSLATORS: The word "manual" stands for manual process
#: tax.js:200 
msgid "manual"     msgstr "" 

但事实并非如此。我在这里做错了什么,或者译者的评论是不是在Python模式下工作?

But it doesn't. Am I doing something wrong here or are translator comments just not working in Python mode?

编辑:我已接受John Flatness的回答是正确的,但我确实找到了解决方法使我仍然可以使用Python模式并提取翻译器注释。它并不完美,因为它实际上在注释中留下了一些语法:

I have accepted John Flatness' answer as the correct one, however I did find a workaround that enables me to still use the Python mode and extract translator comments. It's not perfect, because it actually leaves some of the syntax inside the comments:

在我的 tax.js 文件中:

/*
# This is a translator comment */
gettext("What is this?");

运行此命令:

find . -iname '*.html' -o -iname '*.js' | xargs xgettext --language=Python --from-code=utf-8 --keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 -c

结果为.po文件:

#. This is a translator comment */
#: tax.js:201
msgid "What is this?"
msgstr ""

正如您所看到的,唯一的问题是:

As You can see, the only problems are that:


  1. 我必须在2行写评论

  2. 评论终结者 * / 留在译者评论中

  1. I have to write the comment in 2 lines
  2. The comment terminator */ is left in the translator comments

但在大多数情况下,这不应该是一个大问题。

This should not be much of an issue in most cases, though.

推荐答案

问题是你告诉 xgettext 该来源是Python,当它真的是JavaScript。

The problem is that you're telling xgettext that the source is Python, when it's really JavaScript.

这可能使它在很多情况下足够好,但是我认为这里有什么绊脚石是Python没有不使用 // 进行单行评论,它使用

This may make it work "well enough" for many cases, but I'd assume what's tripping things up here is that Python doesn't do one-liner comments with //, it uses #.

在Github上有一个项目,它为gettext工具添加了javascript支持。我不确定它的当前状态,你必须从源代码构建才能使用它。否则,我想您可以尝试其他语言 xgettext 支持具有更多C / C ++ / Java语法的语言。

There's a project on Github that adds javascript support to the gettext tools. I'm not sure of its current status, and you'd have to build from source to use it. Otherwise, I suppose you could try other languages that xgettext does support that have more C/C++/Java-like syntax.

这篇关于使用JavaScript中的xgettext提取翻译者注释(在Python模式下)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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