42 種語言的 gettext Plural-Forms,逐一核對數字與 CLDR 資料

語言

gettext 的複數條目將各變體存放在編號槽位中,例如 msgstr[0]、msgstr[1] 依此類推,而檔案標頭中的 Plural-Forms 行是一個小型 C 語言公式,用於為某個數字選擇對應的槽位。對於 Polyglot 1.4.0,我們需要為它所翻譯的 42 種語言都取得該公式,且每個槽位必須存放 CLDR 為相同數字所提供的變體;CLDR 是 Android、ICU 以及我們自身檢查背後的複數資料來源。以下是該表格,以及我們的檢查方式。

每個 CLDR 有複數規則的語言的標題,以及您自己的檢查器,都在每個語言的 Plural-Forms。

我們的檢查方式

舊資料不一致之處

我們首先針對 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」被誤譯為「登出」。

存放位置

Polyglot 1.4.0 會將這些標頭寫入其產生的每個 .po 檔案,並將每個形式放入對應的欄位。為何用於多個數字的單一形式必須顯示數字,請見先前的說明;檢查機制本身免費提供於 translation-checks,自 1.3.0 版起,它也能讀取您現有的 .po 檔案,並指出其 Plural-Forms 是否將 CLDR 規定應有不同形式的數字放入同一欄位。