使用 xgettextt 和 --extract-all 处理复数
将 --extract-all
与 xgettext
一起使用不适用于复数。 使用 I18n C++ hello world withplurals 的答案作为这里的 C++ 代码使用 xgettext 的两个测试。
cat >helloplurals.cxx <<EOF
// hellopurals.cxx
#include <libintl.h>
#include <locale.h>
#include <iostream>
int main (){
setlocale(LC_ALL, "");
bindtextdomain("helloplurals", ".");
textdomain( "helloplurals");
for (int ii=0; ii<5; ii++)
printf(ngettext("Hello world with %d moon.\n", "Hello world with %d moons.\n", ii), ii);
EOF
xgettext --package-name helloplurals --package-version 1.1 --default-domain helloplurals --output helloplurals.pot helloplurals.cxx
xgettext --extract-all --package-name helloplurals --package-version 1.1 --default-domain helloplurals --output helloplurals-ea.pot helloplurals.cxx
没有 --extract-all
的文件按预期工作,包括复数的处理:
#: helloplurals.cxx:10
#, c-format
msgid "Hello world with %d moon.\n"
msgid_plural "Hello world with %d moons.\n"
msgstr[0] ""
msgstr[1] ""
当 --extract-all
添加到命令行时,生成的 POT 文件不会。 相反,有单独的条目:
#: helloplurals.cxx:10
#, c-format
msgid "Hello world with %d moon.\n"
msgstr ""
#: helloplurals.cxx:10
#, c-format
msgid "Hello world with %d moons.\n"
msgstr ""
直接传递给 gettext()
之类的函数的字符串文字可以正确处理复数消息,如 xgettext
的第一个使用示例所示。
对于未直接传递给类似 gettext() 的函数之一的字符串文字 将选项 --extract-all
与 xgettext
一起使用可用于在 POT 文件中生成条目。
如何处理未直接传递给 gettext()
的字符串文字,例如源代码中的函数也包含直接传递给 gettext()
的复数字符串文字> 像函数一样生成复数条目:msgid_plural
和msgstr[]
?
Using --extract-all
with xgettext
does not work with plurals. Using the answer to I18n C++ hello world with plurals as the C++ code here are two tests using xgettext
.
cat >helloplurals.cxx <<EOF
// hellopurals.cxx
#include <libintl.h>
#include <locale.h>
#include <iostream>
int main (){
setlocale(LC_ALL, "");
bindtextdomain("helloplurals", ".");
textdomain( "helloplurals");
for (int ii=0; ii<5; ii++)
printf(ngettext("Hello world with %d moon.\n", "Hello world with %d moons.\n", ii), ii);
EOF
xgettext --package-name helloplurals --package-version 1.1 --default-domain helloplurals --output helloplurals.pot helloplurals.cxx
xgettext --extract-all --package-name helloplurals --package-version 1.1 --default-domain helloplurals --output helloplurals-ea.pot helloplurals.cxx
The one without --extract-all
works as expected including the handling of plurals:
#: helloplurals.cxx:10
#, c-format
msgid "Hello world with %d moon.\n"
msgid_plural "Hello world with %d moons.\n"
msgstr[0] ""
msgstr[1] ""
When --extract-all
is added to the command line the resulting POT file does not. Instead there are separate entries:
#: helloplurals.cxx:10
#, c-format
msgid "Hello world with %d moon.\n"
msgstr ""
#: helloplurals.cxx:10
#, c-format
msgid "Hello world with %d moons.\n"
msgstr ""
String literals that are passed directly to the gettext()
like functions properly handle plural messages as shown in the first example use of xgettext
.
For string literals that are not passed directly to one of the gettext()
like functions
the use of the option --extract-all
with xgettext
can be used to produce the entries in a POT file.
How does one get the handling of string literals that are not passed directly to the gettext()
like functions in source that also contains plural string literals that are passed directly to gettext()
like function to produce the plural entries: msgid_plural
and msgstr[]
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 xgettext 不支持这一点。 如果您传递 --extract-all,它将忽略出现字符串的任何上下文。 您可以考虑将此报告为错误。
无论如何,我建议显式标记所有字符串。 有良好的工具支持可以相当快地做到这一点。
I don't think xgettext supports that. If you pass --extract-all, it will ignore any context where a string occurs. You may consider reporting this as bug.
I would recommend to mark up all strings explicitly, anyway. There is good tool support to do that fairly quickly.