简体   繁体   English

xgettext 错误地推断出 cpp 文件中的“c 格式”

[英]xgettext incorrectly infers 'c-format' in cpp files

I have a bunch of.cpp files which contain text including a literal percent sign.我有一堆 .cpp 文件,其中包含包含文字百分号的文本。 Those files don't use printf at all, they use iostream stuff:这些文件根本不使用printf ,它们使用iostream的东西:

std::cout <<  _( "50 % of 10 is 5" ) << std::endl;

However, strings containing % are still marked as c-format by xgettext :但是,包含%的字符串仍被xgettext标记为c-format

#: test.cpp:5
#, c-format
msgid "50 % of 10 is 5"
msgstr ""

This template then gets processed by msgmerge and translated, and translation tools (eg Poedit) complains about such entries:然后这个模板被msgmerge处理并翻译,翻译工具(例如 Poedit)抱怨这样的条目:

#: test.cpp:5
#, c-format
msgid "50 % of 10 is 5"
msgstr "50 % de 10 est 5"

Format specification in 'msgid' and 'msgstr' does not match “msgid”和“msgstr”中的格式规范不匹配

Manually removing the #, c-format comments helps, but they come back after every merge.手动删除#, c-format注释会有所帮助,但它们会在每次合并后返回。 How can I force xgettext or msgmerge to drop those comments?如何强制xgettextmsgmerge删除这些评论? I know I can just filter them out with sed , but is there a smarter way, which would keep such comments for strings coming from C files?我知道我可以用sed过滤掉它们,但是有没有更聪明的方法可以保留来自 C 文件的字符串的此类注释?

The gettext documentation talks about this exact same issue here: https://www.gnu.org/software/gettext/manual/html_node/c_002dformat-Flag.html gettext文档在这里讨论了这个完全相同的问题: https://www.gnu.org/software/gettext/manual/html_node/c_002dformat-Flag.html

According to the docs, you should use this special comment before the lines:根据文档,您应该在以下行之前使用此特殊注释:

xgettext:no-c-format

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM