gettext Plural-Forms for 42 languages, checked number by number against CLDR
Languages
A gettext plural entry keeps its forms in numbered slots, msgstr[0], msgstr[1] and on, and the Plural-Forms line in the file's header is a small C formula that picks the slot for a number. For Polyglot 1.4.0 we needed that formula for all 42 languages it translates into, and each slot had to hold the form that CLDR, the plural data behind Android, ICU and our own checks, gives the same numbers. Here is the table, and how we checked it.
The header for every language CLDR has plural rules for, and a checker for your own, are on Plural-Forms for every language.
How we checked it
- Every whole number from 0 to 10,000: Python's own gettext evaluated each formula, and the slot it picked had to hold the form Babel 2.18's CLDR data gives that number. 41 languages matched; Haitian Creole is the one exception, and a deliberate one (below).
- GNU msgfmt --check on a file in each of the 42 languages, with a form in every slot: no errors.
- A real run: the example app's gettext file, translated by our local model into nine languages, each file compiled and read back with Python's gettext. Russian shows "Пропущена 21 привычка" but "Пропущено 22 привычки", Romanian "21 de obiceiuri" but "101 obiceiuri", and Arabic has all six of its forms in their places.
Where older data disagreed
We first checked against Babel 2.10, which carries CLDR 41 from 2022. Three languages came out differently, and in each the newer data and the language itself agree with the table:
- Romanian: CLDR 41 puts 101 with 20 and 100, which take "de" ("100 de zile"); current CLDR puts it with 2 to 19, which do not. Our model wrote "101 obiceiuri ratate", without "de".
- Hebrew: CLDR 41 still had a "many" form for 20, 30, 40 and so on. Later CLDR dropped it, so Hebrew has three slots: one, two and other.
- Haitian Creole was not in that data at all. Current CLDR gives it two forms, one for 0 and 1 and other for the rest, but Haitian nouns do not change for number ("1 liv", "2 liv"), so we kept a single slot, as Polyglot does in its other formats.
What the slots hold
- Russian, Ukrainian and Polish have three slots, and the third is CLDR's "many" (0, 5 to 20, 25…), not "other": "other" is for fractions only. Polish "one" is 1 alone; 21 is "many".
- Czech and Slovak: their "many" is for fractions only, so the third slot is "other".
- Spanish, French, Italian and Portuguese have a "many" form for exact millions; gettext's two slots cannot tell it apart, so it shares "other".
- French, Portuguese, Persian, Armenian, Amharic, Kannada and Punjabi use "one" for 0 as well, hence
plural=(n > 1).
The table
| Language | gettext | Plural-Forms | msgstr[0], [1]… |
|---|---|---|---|
| Amharic | am | nplurals=2; plural=(n > 1); | one, other |
| Arabic | ar | nplurals=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 |
| Armenian | hy | nplurals=2; plural=(n > 1); | one, other |
| Bulgarian | bg | nplurals=2; plural=(n != 1); | one, other |
| Chinese (Simplified) | zh_CN | nplurals=1; plural=0; | other |
| Chinese (Traditional) | zh_TW | nplurals=1; plural=0; | other |
| Czech | cs | nplurals=3; plural=(n == 1) ? 0 : ((n >= 2 && n <= 4) ? 1 : 2); | one, few, other |
| Dutch | nl | nplurals=2; plural=(n != 1); | one, other |
| Filipino | fil | nplurals=2; plural=(n != 1 && n != 2 && n != 3 && (n % 10 == 4 || n % 10 == 6 || n % 10 == 9)); | one, other |
| Finnish | fi | nplurals=2; plural=(n != 1); | one, other |
| French | fr | nplurals=2; plural=(n > 1); | one, other |
| German | de | nplurals=2; plural=(n != 1); | one, other |
| Greek | el | nplurals=2; plural=(n != 1); | one, other |
| Haitian Creole | ht | nplurals=1; plural=0; | other |
| Hebrew | he | nplurals=3; plural=(n == 1) ? 0 : ((n == 2) ? 1 : 2); | one, two, other |
| Hungarian | hu | nplurals=2; plural=(n != 1); | one, other |
| Indonesian | id | nplurals=1; plural=0; | other |
| Italian | it | nplurals=2; plural=(n != 1); | one, other |
| Japanese | ja | nplurals=1; plural=0; | other |
| Kannada | kn | nplurals=2; plural=(n > 1); | one, other |
| Khmer | km | nplurals=1; plural=0; | other |
| Korean | ko | nplurals=1; plural=0; | other |
| Macedonian | mk | nplurals=2; plural=(n % 10 == 1 && n % 100 != 11) ? 0 : 1; | one, other |
| Malay | ms | nplurals=1; plural=0; | other |
| Norwegian Bokmål | nb | nplurals=2; plural=(n != 1); | one, other |
| Oromo | om | nplurals=2; plural=(n != 1); | one, other |
| Persian | fa | nplurals=2; plural=(n > 1); | one, other |
| Polish | pl | nplurals=3; plural=(n == 1) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : 2); | one, few, many |
| Portuguese (Brazil) | pt_BR | nplurals=2; plural=(n > 1); | one, other |
| Punjabi | pa | nplurals=2; plural=(n > 1); | one, other |
| Romanian | ro | nplurals=3; plural=(n == 1) ? 0 : ((n == 0 || n % 100 >= 1 && n % 100 <= 19) ? 1 : 2); | one, few, other |
| Russian | ru | nplurals=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 |
| Scottish Gaelic | gd | nplurals=4; plural=(n == 1 || n == 11) ? 0 : ((n == 2 || n == 12) ? 1 : ((n > 2 && n < 20) ? 2 : 3)); | one, two, few, other |
| Serbian (Cyrillic) | sr | nplurals=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 |
| Slovak | sk | nplurals=3; plural=(n == 1) ? 0 : ((n >= 2 && n <= 4) ? 1 : 2); | one, few, other |
| Slovenian | sl | nplurals=4; plural=(n % 100 == 1) ? 0 : ((n % 100 == 2) ? 1 : ((n % 100 == 3 || n % 100 == 4) ? 2 : 3)); | one, two, few, other |
| Spanish | es | nplurals=2; plural=(n != 1); | one, other |
| Swedish | sv | nplurals=2; plural=(n != 1); | one, other |
| Thai | th | nplurals=1; plural=0; | other |
| Turkish | tr | nplurals=2; plural=(n != 1); | one, other |
| Ukrainian | uk | nplurals=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 |
| Vietnamese | vi | nplurals=1; plural=0; | other |
What the real run found
Arabic's zero and two forms were refused at first for leaving out %(n)s. A form for a single number may do that, and the Arabic dual says "two" by itself, but our check only knew %d and {count} as the count. It now knows Python's %(n)s and %(count)d as well, which also means a Russian "one" without the number is refused, since Russian "one" is also 21 and 31. The same run had our model read its translations for meaning, and it caught Czech "Unsubscribe" written as "log out".
Where it lives
Polyglot 1.4.0 writes these headers into every .po file it produces and puts each form in its slot. Why a form used for several numbers must show the number is in an earlier note, and the checks themselves are free in translation-checks, which since 1.3.0 also reads a .po file you already have and says when its Plural-Forms puts numbers in one slot that CLDR gives different forms.