Skip to content
Docs

Writing ICU plurals

Plurals, selects and placeholders in ICU messages, per language, and the mistakes the checks catch.

Everyone5 min read

Strings that depend on a number or a choice, such as "1 file" and "5 files", are written in ICU MessageFormat. This guide covers the syntax, how languages differ in their plural forms, and the warnings Localizator shows when a value is wrong. For the complete syntax, see ICU MessageFormat in the ICU User Guide and FormatJS ICU syntax (Localizator checks values with the FormatJS parser).

Placeholders

A placeholder is a name in braces. The app replaces it with a value at run time:

Welcome back, {name}!

Keep every placeholder of the source in the translation, with exactly the same name. Its position can change to suit the language:

Bon retour, {name} !

Never translate the name inside the braces: {nom} is a different placeholder, and the app has no value for it.

Plurals

A plural picks a variant by a number:

{count, plural, one {# file} other {# files}}
  • count is the number's placeholder name. Keep it as is.
  • plural is a keyword. Keep it in English.
  • one and other are plural categories: which variant to use for which number. They are keywords too, never translated.
  • Each variant is in braces and is free text, which you translate.
  • # is replaced by the number, formatted for the language.

other is the fallback every language has. Write it in every plural.

Exact numbers

=0, =1 and so on match one exact number, before the categories are considered:

{count, plural, =0 {No files} one {# file} other {# files}}

Use =0 for an empty state. Use one rather than =1 for "one", because in some languages one covers more numbers than 1.

Other placeholders inside a plural

Variants can contain other placeholders:

{count, plural, one {# file in {folder}} other {# files in {folder}}}

Plural categories per language

Languages need different numbers of variants. A translation uses the categories of its own language, not the source's. The categories are zero, one, two, few, many and other, following the Unicode CLDR rules that browsers and Intl.PluralRules use:

LanguageCategoriesExamples
English, Germanone, other1 → one; 0, 2, 5 → other
Frenchone, many, other0 and 1 → one; 2, 5 → other; 1,000,000 → many
Spanish, Italianone, many, other1 → one; 0, 2, 5 → other; 1,000,000 → many
Russian, Ukrainianone, few, many, other1, 21 → one; 2, 22 → few; 0, 5, 25 → many; 1.5 → other
Polishone, few, many, other1 → one; 2, 22 → few; 0, 5, 21, 25 → many; 1.5 → other
Czechone, few, many, other1 → one; 2–4 → few; fractions → many; 0, 5 → other
Arabiczero, one, two, few, many, other0 → zero; 1 → one; 2 → two; 5 → few; 21 → many
Japanese, ChineseotherEvery number

Note that in French, 0 uses one: "0 fichier". Add =0 if you want a different text for zero.

The same English source in Russian:

{count, plural, one {# файл} few {# файла} many {# файлов} other {# файла}}

And in Japanese, where one variant is enough:

{count, plural, other {# 個のファイル}}

Select

select picks a variant by a word instead of a number, for example a gender or a type:

{gender, select, female {She replied} male {He replied} other {They replied}}

The selectors (female, male, other) are fixed by the app's code: never translate them, and keep other.

Nesting

Plurals and selects can be nested. Put the whole sentence in each variant instead of splitting it, so every language can arrange words its own way:

{gender, select,
  female {{count, plural, one {She has # new message} other {She has # new messages}}}
  other {{count, plural, one {They have # new message} other {They have # new messages}}}
}

Ordinals

selectordinal picks a variant for ordinal numbers (1st, 2nd, 3rd). English uses one, two, few and other here:

{place, selectordinal, one {#st} two {#nd} few {#rd} other {#th}}

Apostrophes

In ICU, an apostrophe before a brace starts quoted text, so l'{name} breaks the message. Write two apostrophes (l''{name}), or use the typographic apostrophe ’, which ICU leaves alone:

{count, plural, one {l’album de {name} a # photo} other {l’album de {name} a # photos}}

Numbers, dates and times

A placeholder can say how its value is formatted. The app formats it for the reader's language, so keep the whole placeholder as it is:

Total: {price, number, ::currency/EUR}
Saved on {when, date, medium} at {when, time, short}
{share, number, percent} done

Only the text around it is translated: Gesamt: {price, number, ::currency/EUR}.

Tags

Tags mark text the app turns into formatting or a link. Keep the tags and their names; translate the text between them, and move them with it:

Read the <link>guide</link> first.
Lies zuerst den <link>Leitfaden</link>.

Keep every opening tag with its closing one: a tag left open (<link>Leitfaden) breaks the message in the app. Localizator flags it as invalid ICU syntax only inside a plural or select.

Common mistakes and their warnings

Localizator checks every value when it's written and keeps it even when a check fails (see Statuses & checks). The cell editor runs the same checks while you type and underlines a syntax error where it is. What each mistake produces:

MistakeExampleWarning
A missing closing brace{count, plural, one {# fichier} other {# fichiers}Invalid ICU syntax, and usually missing placeholders too
A variant without braces… other # fichiers}Invalid ICU syntax
An apostrophe before a brace{count, plural, one {l'{name} …} …}Invalid ICU syntax
Translated keyword{count, pluriel, un {…} autre {…}}Missing placeholders: the names of the source. Not seen as ICU, so there's no syntax error
Renamed placeholder{nombre, plural, …} or {nom}Missing placeholders: the source's name and Extra placeholders: the new one
A placeholder left out of a variantone {# fichier} when the source has {folder} thereMissing placeholders: {folder}
Plural replaced by plain text# fichiersMissing placeholders: {count}

Some mistakes are not caught, so check them by eye:

  • Translated categories or selectors, such as un instead of one. The syntax is valid, but the app never picks that variant.
  • A missing other. The message parses, but a number with no matching variant has nothing to show.
  • Categories the language doesn't use, or ones it needs and are missing, such as a Russian plural without few and many. No warning is stored, but the cell editor points them out while you type ("Missing plural forms for ru: few, many", "Not used in de: few"). Categories only very large numbers use, such as French many for 1,000,000, aren't asked for.

Warnings that are fine to leave

Placeholders are compared by name and by how many times they appear. A language with more or fewer plural variants than the source repeats a placeholder more or fewer times, which is reported even though the value is correct:

  • Russian with four variants that each contain {folder}, from an English source with two, shows Extra placeholders: {folder}, {folder}.
  • Japanese with only other shows Missing placeholders: {folder}.

If the plural is otherwise right, keep the value and mark it reviewed.

Related