Plural messages in apps: '1 items' and the ICU fix
Short answer: Building app text like count + " items" produces "1 items" in English and much worse in other languages, because languages have different plural forms: English has two, while Arabic, for example, has six categories in Unicode's data. Use ICU MessageFormat, which keeps each message's plural and select variants in one string, with an other case always present. Pass numbers and genders as arguments, let the library pick the form, and give translators whole sentences rather than fragments.
Why string-joining breaks
Most apps start with text assembled in code:
label = count + " item" + (count == 1 ? "" : "s") + " in your basket"
It works in English, mostly. Then the app is translated, and the trouble begins. Languages differ in how many plural forms they have and which numbers use which form. Some have special forms for two, or for numbers ending in certain digits. Word order changes too, so a sentence glued from fragments may not be translatable at all.
The Unicode Common Locale Data Repository (CLDR) publishes plural rules per language. English cardinal numbers use two categories, one and other. Arabic uses six: zero, one, two, few, many and other, with rules based on the number. A single if for one versus many can't handle that.
What ICU MessageFormat does
ICU, the widely used Unicode internationalisation library, defines a message syntax that keeps all variants of a sentence together. Its user guide explains that a plural argument selects sub-messages based on a numeric value, using the plural rules of the given language, and a select argument chooses sub-messages from a fixed set of keywords, such as a gender or a status.
The basket message becomes:
{count, plural,
=0 {Your basket is empty}
one {# item in your basket}
other {# items in your basket}
}
The # is replaced by the number, formatted for the locale. =0 matches exactly zero, while one and other are plural categories. A translator writing Arabic adds the categories Arabic needs; the code doesn't change.
Rules that keep messages safe
- Always include
other. It's the fallback category in every language, and messages are invalid without it. - Use categories, not numbers, for general cases.
oneisn't always just the number 1 in every language. Use=1only when you really mean exactly one. - Keep whole sentences inside each branch. Don't put a plural in the middle of a fragment that's joined to other text in code.
- Pass raw values, not pre-formatted text. Give the message the number, and let it format digits and separators for the locale.
Select for gender and status
The select type handles choices that aren't numeric. For example, a notification about a staff member:
{gender, select,
female {{name} updated her availability}
male {{name} updated his availability}
other {{name} updated their availability}
}
As with plurals, other is required. In many apps, rewriting the sentence to avoid gender altogether, such as "Availability updated by {name}", is simpler and just as clear. Use select where the language needs it.
You can also use select for statuses, such as order states, so each state has a complete, translatable sentence.
Nesting, carefully
ICU allows messages inside messages, such as a plural inside a select. The ICU user guide's example nests guest counts inside host gender for a party invitation. It works, but complex nesting is hard for translators. Keep nesting shallow, and prefer splitting into separate messages when a sentence grows unwieldy.
Where to use it in your stack
You rarely need to write a parser. Common routes:
- Web and JavaScript: libraries implement ICU MessageFormat, and many translation management platforms understand its syntax. The browser's built-in
Intl.PluralRulesgives you the plural category for a number in a locale, which these libraries use underneath. - Mobile: Android has plural resources, and iOS has its own pluralisation support in string catalogs. Both follow CLDR categories. Cross-platform frameworks often adopt ICU-style syntax.
- Back end: ICU libraries exist for Java, C and C++, and ports for most other languages.
If you're starting from scratch, pick one library per platform and write a short internal guide with two or three example messages, so every developer formats plurals and selects the same way. Consistency matters more than which library you choose, because it keeps translation files predictable.
Whichever you use, keep the same message keys and syntax across platforms where possible, so translators see consistent strings.
Help translators do it right
Translation quality depends on what translators receive:
- Send complete messages with their plural and select branches.
- Add a short note per message: where it appears and what each argument holds.
- Use clear argument names, such as
{itemCount}rather than{0}. - Make sure your translation tool validates ICU syntax, so a missing brace doesn't crash the app.
Test with real numbers
Test each plural message in each language with a spread of values: 0, 1, 2, a few, and larger numbers like 11, 21, 100 and 101. For languages like Arabic, CLDR's examples per category show which numbers fall where. Automated tests that render each message with these values catch missing categories early.
A worked example
Imagine a hypothetical Denver salon-booking app expanding into Spanish and Arabic. Its strings were joined in code, giving "1 appointments" in English and broken sentences in translation. The team moved every count-based message to ICU MessageFormat, added notes for translators, switched staff notifications to gender-neutral wording, and added tests rendering each message with a standard list of numbers. The Arabic translator filled in all six plural categories without any code changes.
FAQ
Is this only needed for multilingual apps?
No. Even English-only apps benefit: no more "1 items", and adding a language later becomes much easier.
What about ordinal numbers like 1st and 2nd?
ICU supports an ordinal type with its own rules per language. Use it rather than adding suffixes in code.
Can I mix ICU messages with plain strings?
Yes. Plain strings stay plain. Use ICU syntax only where values change the wording.
Do numbers inside messages get formatted?
Yes, the # placeholder and number arguments are formatted for the locale.
If your app's text breaks around counts or translations, send us a few of your strings and we'll suggest a structure.