42 种语言的 gettext Plural-Forms,逐一对照 CLDR 进行核对

语言

gettext 复数条目将各形式保存在编号槽位中,如 msgstr[0]、msgstr[1] 等,而文件头部的 Plural-Forms 行是一个小型 C 语言公式,用于为某个数字选择槽位。对于 Polyglot 1.4.0,我们需要为其翻译的 42 种语言都提供该公式,并且每个槽位必须保存 CLDR(Android、ICU 和我们自身检查所依据的复数数据)为相同数字提供的形式。以下是该表格,以及我们的核对方法。

每种语言的复数形式中提供了所有 CLDR 定义了复数规则的语言的标题,以及用于检查您自定义规则的校验器。

我们的核对方法

旧数据存在分歧之处

我们首先对照 Babel 2.10 进行核对,该版本包含 2022 年的 CLDR 41。三种语言的结果不同,而在每种情况下,较新的数据和语言本身都与表格一致:

槽位内容

表格

语言gettext复数形式msgstr[0], [1]…
阿姆哈拉语amnplurals=2; plural=(n > 1);one, other
阿拉伯语arnplurals=6; plural=(n == 0) ? 0 : ((n == 1) ? 1 : ((n == 2) ? 2 : ((n % 100 >= 3 && n % 100 <= 10) ? 3 : ((n % 100 >= 11) ? 4 : 5))));zero, one, two, few, many, other
亚美尼亚语hynplurals=2; plural=(n > 1);one, other
保加利亚语bgnplurals=2; plural=(n != 1);one, other
简体中文zh_CNnplurals=1; plural=0;other
繁体中文zh_TWnplurals=1; plural=0;other
捷克语csnplurals=3; plural=(n == 1) ? 0 : ((n >= 2 && n <= 4) ? 1 : 2);one, few, other
荷兰语nlnplurals=2; plural=(n != 1);one, other
菲律宾语filnplurals=2; plural=(n != 1 && n != 2 && n != 3 && (n % 10 == 4 || n % 10 == 6 || n % 10 == 9));one, other
芬兰语finplurals=2; plural=(n != 1);one, other
法语frnplurals=2; plural=(n > 1);one, other
德语denplurals=2; plural=(n != 1);one, other
希腊语elnplurals=2; plural=(n != 1);one, other
海地克里奥尔语htnplurals=1; plural=0;other
希伯来语henplurals=3; plural=(n == 1) ? 0 : ((n == 2) ? 1 : 2);one, two, other
匈牙利语hunplurals=2; plural=(n != 1);one, other
印尼语idnplurals=1; plural=0;other
意大利语itnplurals=2; plural=(n != 1);one, other
日语janplurals=1; plural=0;other
卡纳达语knnplurals=2; plural=(n > 1);one, other
高棉语kmnplurals=1; plural=0;other
韩语konplurals=1; plural=0;other
马其顿语mknplurals=2; plural=(n % 10 == 1 && n % 100 != 11) ? 0 : 1;one, other
马来语msnplurals=1; plural=0;other
挪威博克马尔语nbnplurals=2; plural=(n != 1);one, other
奥罗莫语omnplurals=2; plural=(n != 1);one, other
波斯语fanplurals=2; plural=(n > 1);one, other
波兰语plnplurals=3; plural=(n == 1) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : 2);one, few, many
葡萄牙语(巴西)pt_BRnplurals=2; plural=(n > 1);one, other
旁遮普语panplurals=2; plural=(n > 1);one, other
罗马尼亚语ronplurals=3; plural=(n == 1) ? 0 : ((n == 0 || n % 100 >= 1 && n % 100 <= 19) ? 1 : 2);one, few, other
俄语runplurals=3; plural=(n % 10 == 1 && n % 100 != 11) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : 2);one, few, many
苏格兰盖尔语gdnplurals=4; plural=(n == 1 || n == 11) ? 0 : ((n == 2 || n == 12) ? 1 : ((n > 2 && n < 20) ? 2 : 3));one, two, few, other
塞尔维亚语(西里尔字母)srnplurals=3; plural=(n % 10 == 1 && n % 100 != 11) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : 2);one, few, other
斯洛伐克语sknplurals=3; plural=(n == 1) ? 0 : ((n >= 2 && n <= 4) ? 1 : 2);one, few, other
斯洛文尼亚语slnplurals=4; plural=(n % 100 == 1) ? 0 : ((n % 100 == 2) ? 1 : ((n % 100 == 3 || n % 100 == 4) ? 2 : 3));one, two, few, other
西班牙语esnplurals=2; plural=(n != 1);one、other
瑞典语svnplurals=2; plural=(n != 1);one、other
泰语thnplurals=1; plural=0;other
土耳其语trnplurals=2; plural=(n != 1);one、other
乌克兰语uknplurals=3; plural=(n % 10 == 1 && n % 100 != 11) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : 2);one、few、many
越南语vinplurals=1; plural=0;other

实际运行发现的问题

阿拉伯语的零数和双数形式起初因未包含 %(n)s 而被拒绝。表示单一数字的形式可以省略该占位符,且阿拉伯语的双数形式本身已表达“两个”的含义,但我们的检查机制此前仅识别 %d 和 {count} 作为计数占位符。现在它也识别 Python 的 %(n)s 和 %(count)d,这意味着俄语中未包含数字的“one”形式也会被拒绝,因为俄语的“one”同样适用于 21 和 31。在同一次运行中,我们的模型读取了其翻译内容以检查含义,并发现捷克语的“Unsubscribe”被误译为“log out”。

代码位置

Polyglot 1.4.0 会将这些头部信息写入其生成的每个 .po 文件,并将每种复数形式放入对应的位置。为何用于多个数字的复数形式必须显示数字,请参见早前的说明;检查机制本身可在 translation-checks 中免费获取,自 1.3.0 版本起,它还能读取您已有的 .po 文件,并指出其 Plural-Forms 将 CLDR 规定为不同复数形式的数字归入同一位置的情况。