Plural Rules in ICU MessageFormat
Master ICU plural rules including all six CLDR plural categories (zero, one, two, few, many, other) and how they vary across languages. Includes examples for English, Arabic, and Polish.
Detailed Explanation
Understanding ICU Plural Rules
Pluralization is one of the most powerful features of ICU MessageFormat. Unlike naive approaches that only handle singular vs. plural, ICU uses the Unicode CLDR plural rules which define up to six categories depending on the language.
The Six Plural Categories
| Category | Used By | Example Numbers (English) |
|---|---|---|
zero |
Arabic, Latvian | N/A in English |
one |
English, German, Spanish | 1 |
two |
Arabic, Hebrew, Slovenian | N/A in English |
few |
Polish, Czech, Russian | N/A in English |
many |
Polish, Arabic, Russian | N/A in English |
other |
All languages (required) | 0, 2, 3, 4, 5, ... |
English Plural (2 categories)
English only uses one (for exactly 1) and other (for everything else):
{count, plural,
one {You have # new notification}
other {You have # new notifications}
}
Polish Plural (4 categories)
Polish uses one, few, many, and other:
{count, plural,
one {# plik}
few {# pliki}
many {# plików}
other {# pliku}
}
- 1 plik (one)
- 2, 3, 4 pliki (few)
- 5-21 plików (many)
- 1.5 pliku (other)
Arabic Plural (6 categories)
Arabic uses all six categories:
{count, plural,
zero {لا كتب}
one {كتاب واحد}
two {كتابان}
few {# كتب}
many {# كتاباً}
other {# كتاب}
}
Exact Value Matching with =N
You can match exact numeric values using =N syntax, which takes priority over category matching:
{count, plural,
=0 {Your inbox is empty}
=1 {You have one message}
=42 {You have the answer to everything}
other {You have # messages}
}
The # Placeholder
Inside plural cases, # is replaced with the formatted numeric value:
{count, plural, one {# item} other {# items}}
count=1 -> "1 item"
count=42 -> "42 items"
count=1000 -> "1,000 items" (with locale formatting)
Always Include other
The other category is required in every plural message. It acts as the default fallback when no other category matches. Omitting it will cause runtime errors in most ICU implementations.
Use Case
Application developers implementing multi-language support who need to correctly handle plural forms for languages beyond English, especially when supporting Arabic, Russian, Polish, or other languages with complex plural rules.