Loading...
const label = `${n} ${n === 1 ? 'file' : 'files'}`;
show(label);const rules = new Intl.PluralRules(locale);
const forms = messages[locale].files; // { one, few, many, other }
show(`${n} ${forms[rules.select(n)]}`);Intl.PluralRules returns the plural category for the locale, and translators supply a form for each one.
Intl.PluralRules or an ICU message, not with n === 1 checks.There are six: 'zero', 'one', 'two', 'few', 'many' and 'other'. Each language uses a subset, and 'other' always exists.
Use new Intl.PluralRules(locale, { type: 'ordinal' }), which returns categories such as 'one', 'two', 'few' and 'other' for English suffixes.
Plural. Intl.PluralRules returns 'other' for 0 in English, giving '0 files', while some languages treat zero differently.