【发布时间】:2009-07-10 07:32:07
【问题描述】:
Complete C++ i18n gettext() “hello world” example 具有适用于简单固定字符串的 C++ 代码。我现在正在寻找一个适用于复数的示例程序。此示例代码显示六行。只有一个是英语正确的。它不能正确处理复数。
cat >helloplurals.cxx <<EOF
// hellopurals.cxx
#include <libintl.h>
#include <locale.h>
#include <iostream>
#include <stdio.h>
int main (){
setlocale(LC_ALL, "");
bindtextdomain("helloplurals", ".");
textdomain( "helloplurals");
for (int ii=0; ii<5; ii++)
printf (gettext("Hello world with %d moon.\n"), ii);
}
EOF
g++ -o helloplurals helloplurals.cxx
./helloplurals
GNU gettext() for plural forms 描述了语言处理复数的各种方式,例如:
- 韩语 - 没有复数
- 英语 - 两种形式,单数仅用于一种
- 法语 - 两种形式,单数用于零和一
- 波兰语 - 三种形式,一种特殊情况以及一些以 2、3 或 4 结尾的数字
我的期望是代码将能够专门针对上述所有情况以及此处未列出的其他几种变体工作(给定消息目录)。用英文执行时正确的输出是:
Hello world with 0 moons.
Hello world with 1 moon.
Hello world with 2 moons.
Hello world with 3 moons.
Hello world with 4 moons.
【问题讨论】:
-
引用 JS:“反对者:请提供 cmets。- Jon Skeet 5 月 8 日 9:25”
标签: c++ internationalization gettext