Wielojęzyczność
i18n/plural-rules
Plurals use the locale's plural rules (ICU plural or Intl.PluralRules), never count === 1 ? singular : plural.
umiarkowanastatycznefe-i18n
Dlaczego
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".
Poprawka
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).
Przykłady
// 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}}"Źródła
Fakty
- Identyfikator
i18n/plural-rules- Waga
- umiarkowana
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
jsxvuesvelteastrohtml- Uczy jej skill
fe-i18nInternationalisation- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain i18n/plural-rules