简体   繁体   中英

xgettext incorrectly infers 'c-format' in cpp files

I have a bunch of.cpp files which contain text including a literal percent sign. Those files don't use printf at all, they use iostream stuff:

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

However, strings containing % are still marked as c-format by xgettext :

#: 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:

#: 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

Manually removing the #, c-format comments helps, but they come back after every merge. How can I force xgettext or msgmerge to drop those comments? 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?

The gettext documentation talks about this exact same issue here: 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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