I18n C ++ hello world with plurals [英] I18n C++ hello world with plurals

查看:195
本文介绍了I18n C ++ hello world with plurals的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完成C ++ i18n gettext()hello world示例具有适用于简单固定字符串的C ++代码。我现在正在寻找一个工作与复数的示例程序。此示例代码显示六行。只有一个是正确的英语。它不正确处理复数。

Complete C++ i18n gettext() "hello world" example has C++ code that works for a simple fixed string. I am now looking for an example program that works with plurals. This example code displays six lines. Only one is correct in English. It does not handle the plurals correctly.

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() / a>描述语言处理复数的各种方式,例如:

GNU gettext() for plural forms describes various ways that languages handle plurals for example:


  • 韩语 - 无pluals


  • 法语 - 两种形式,单数用于零和一个

  • 波兰语 - 三种形式,特殊情况
  • Korean - no pluals
  • English - two forms, singular used for one only
  • French - two forms, singular used for zero and one
  • Polish - three forms, special case for one and some numbers ending in 2, 3, or 4

我的期望是代码将能够工作(给定消息)目录)专门针对所有上述情况和这里未列出的几个更多的变化。当用英语执行时,正确的输出是:

My expectation is that the code will be able to work (given message catalogs) specifically for all of the above cases and several more variations not listed here. The correct output when it is executed with English would be:

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.


推荐答案

我不确定你想要什么。如果你的例子稍作修改,给你想要的输出,只需要替换printf行

I'm not sure what you want. If it is slight modification of your example that give your wanted output, just replace the printf line by

printf(ngettext("Hello world with %d moon\n", "Hello world with %d moons\n", ii), ii);

但是因为它是对unwind回答的一个小修改,gettext文档有非常相似的例子, / p>

but as it is a trivial modification of unwind's answer and the gettext documentation has the very similar example,

printf (ngettext ("%d file removed", "%d files removed", n), n);

我不知道这是否真的是你想要的。如果你想使用更多的C ++语法的gettext,你必须寻找像Boost :: Format这样的库。

I wonder if it is really what you wanted. If you want to use gettext with a more C++ syntax, you'll have to look for libraries like Boost::Format.

这篇关于I18n C ++ hello world with plurals的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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