ICU MessageFormat — Advanced Patterns Vocabulary
5 exercises — 5 exercises practising ICU MessageFormat plural rules, select expressions, nested patterns, and date/number format skeletons.
0 / 5 completed
Quick reference: ICU MessageFormat
- Plural pattern — {count, plural, one {# item} other {# items}} — handles grammatical plural forms by language
- Select pattern — {gender, select, male {He commented} female {She commented} other {They commented}} — case matching on a value
- CLDR plural categories — zero, one, two, few, many, other — different languages use different subsets; Arabic uses all 6
1 / 5
A developer asks: "Why do we need ICU MessageFormat for plurals? Can't we just do count === 1 ? 'item' : 'items'?" Which explanation is correct?
The English ternary (singular/plural) breaks catastrophically for Arabic, Polish, Russian, and dozens of other languages — ICU MessageFormat is the only correct solution.
CLDR (Common Locale Data Repository) defines plural categories per language. Arabic: zero (0 items), one (1 item), two (2 items), few (3-10 items), many (11-99 items), other (100+ items) — six completely different phrase forms. Polish: one (1 item), few (2-4, 22-24, ... items), many (5-21, 25-31, ... items), other. English: one (1 item), other (everything else) — only two forms. ICU MessageFormat lets a single pattern in the source language be translated into language-appropriate plural forms by the translator: {count, plural, one {# item} other {# items}} in English becomes 6 cases in Arabic — handled correctly by the ICU runtime for each locale.
Key vocabulary:
• CLDR plural categories — zero/one/two/few/many/other; the universal plural form taxonomy across all languages
• plural rule — the mathematical rule determining which category applies for a given number in a specific language
• ICU runtime — the library evaluating ICU patterns at runtime with actual count values
CLDR (Common Locale Data Repository) defines plural categories per language. Arabic: zero (0 items), one (1 item), two (2 items), few (3-10 items), many (11-99 items), other (100+ items) — six completely different phrase forms. Polish: one (1 item), few (2-4, 22-24, ... items), many (5-21, 25-31, ... items), other. English: one (1 item), other (everything else) — only two forms. ICU MessageFormat lets a single pattern in the source language be translated into language-appropriate plural forms by the translator: {count, plural, one {# item} other {# items}} in English becomes 6 cases in Arabic — handled correctly by the ICU runtime for each locale.
Key vocabulary:
• CLDR plural categories — zero/one/two/few/many/other; the universal plural form taxonomy across all languages
• plural rule — the mathematical rule determining which category applies for a given number in a specific language
• ICU runtime — the library evaluating ICU patterns at runtime with actual count values