使其工作:ICU / php-intl助记符标记“少”用于复数格式化

时间:2014-09-09 16:55:14

标签: icu intl plural

ICU邮件格式似乎对我不起作用。这是一个例子:

$n = 22;
$f = MessageFormatter::create('ru', '{n, plural, one{корова} few{коровы} many{коров} other{коров}}');
echo $n.' '.$f->format(['n' => $n])."\n";

我在输出中得到22 коров,但显然应该得到22 коровы。试过几个ubuntu服务器。

语言:俄语

php-intl版本1.1.0

ICU第52.1版

任何帮助都会受到影响,因为我坚持下去。

1 个答案:

答案 0 :(得分:3)

这是一个令人讨厌的错误,我花了几乎一个小时才搞清楚。好吧,事实证明在ICU 52.1(可能之前也是如此)我们有以下内容:

set34{
    many{
        "v = 0 and i % 10 = 0 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100"
        " = 11..14 @integer 0, 5~19, 100, 1000, 10000, 100000, 1000000, …"
    }
    one{
        "v = 0 and i % 10 = 1 and i % 100 != 11 @integer 1, 21, 31, 41, 51, 6"
        "1, 71, 81, 101, 1001, …"
    }
    other{
        " @integer 2~4, 22~24, 32~34, 42~44, 52~54, 62, 102, 1002, … @decimal"
        " 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …"
    }
}

来源:http://source.icu-project.org/repos/icu/icu/tags/release-52-1/source/data/misc/plurals.txt

因此,2-4,22-24等案例(22 коровы)属于other修饰符,因此您案例的正确语法为{n, plural, one{корова} few{коровы} many{коров} other{коровы}}。我离开了few以便与更新的ICU版本兼容(在这种情况下确实使用了few修饰符)。