Internationalisation
i18n/plural-rules
Plurals use the locale's plural rules (ICU plural or Intl.PluralRules), never count === 1 ? singular : plural.
moderatestaticfe-i18n
Why
English has two plural forms; Polish has four categories (one, few, many, other: 1 plik, 2 pliki, 5 plików, 1,5 pliku), Arabic six, Japanese one. A === 1 test produces wrong text in most languages, and even English needs "0 files", not "0 file".
Fix
Put the plural in the message: {count, plural, one {# file} other {# files}} in ICU syntax (react-intl, FormatJS, vue-i18n with ICU, next-intl, Paraglide) and give translators every category their language needs. Without a library, select the form with new Intl.PluralRules(locale).select(n).
Examples
// bad
`${n} ${n === 1 ? 'file' : 'files'}`
// good
t('files', { count: n }) // en: "{count, plural, one {# file} other {# files}}"
// pl: "{count, plural, one {# plik} few {# pliki} many {# plików} other {# pliku}}"Sources
Facts
- Id
i18n/plural-rules- Severity
- moderate
- Check
- static checked in the source by
audit - Applies to
jsxvuesvelteastrohtml- Taught by the skill
fe-i18nInternationalisation- Since version
- 0.1.0
Read it in the terminal
npx github:dawidolko/frontend-skills explain i18n/plural-rules