
Reglas de plural CLDR: valide categorías de i18n entre idiomas
El inglés tiene 2 formas plurales, el árabe 6 y el ruso 4. Si su configuración solo gestiona 'one' y 'other', su aplicación falla en la mayoría de los idiomas. Esta guía explica CLDR y cómo validarlo.
¿Qué son las reglas de plural CLDR?
Unicode CLDR (Common Locale Data Repository) define seis categorías: zero, one, two, few, many y other. Cada idioma utiliza un subconjunto con reglas numéricas concretas. El inglés usa one —exactamente 1— y other —todo lo demás—. Muchos idiomas son más complejos; equivocarse genera texto gramaticalmente incorrecto y una impresión poco profesional.
// English has 2 plural forms: one, other
// "1 item" vs "2 items"
// But many languages have more:
// Arabic: 6 forms (zero, one, two, few, many, other)
// Polish: 3 forms (one, few, other)
// Japanese: 1 form (other)
// Czech: 3 forms (one, few, other)
// If you only provide "one" and "other",
// Arabic and Polish users see broken text.Las seis categorías de plural
CLDR define exactamente seis categorías. No todos los idiomas las usan todas: el inglés solo dos y el árabe las seis. Sus archivos deben incluir las que necesite cada idioma, o los usuarios verán bloqueos, claves sin procesar o gramática incorrecta.
// CLDR defines 6 plural categories:
// zero - 0 items (Arabic, Latvian)
// one - 1 item (most languages)
// two - 2 items (Arabic, Welsh)
// few - 2-4 items (Polish, Czech, Russian)
// many - 5-19 items (Arabic, Polish, Russian)
// other - everything else (required for ALL languages)
// Examples by language:
// English: one, other (2 forms)
// French: one, many, other (3 forms)
// Arabic: zero, one, two, few, many, other (6 forms)
// Japanese: other (1 form)
// Polish: one, few, many, other (4 forms)
// Russian: one, few, many, other (4 forms)Categorías plurales por idioma
Referencia rápida de las categorías necesarias en idiomas de destino habituales. Utilícela al definir las formas en sus archivos de traducción.
// MISTAKE 1: Only providing "one" and "other"
// en.json
{
"items_one": "{{count}} item",
"items_other": "{{count}} items"
}
// This breaks for Arabic (missing zero, two, few, many)
// MISTAKE 2: Hardcoded plural logic
// WRONG:
const text = count === 1 ? "1 item" : `${count} items`
// This fails for languages where "1" isn't the only "one" form
// MISTAKE 3: Missing "other" category
// "other" is REQUIRED for every language
// Without it, some numbers show raw keys
// MISTAKE 4: Translating plural RULES instead of text
// The CLDR rules (one, few, many) are universal
// Only the TEXT after each rule should be translatedValidación automatizada de plurales
i18n-validate comprueba que cada clave plural defina todas las categorías CLDR necesarias para el idioma de destino. Si su archivo ruso solo tiene 'one' y 'other', señala la ausencia de 'few' y 'many' como errores. Ejecútelo en CI para detectarlos antes que los usuarios.
# Validate plural forms match CLDR requirements
npx i18n-validate --check-plurals \
--source locales/en.json \
--targets 'locales/*.json'
# Output:
# locales/ar.json:
# items: missing plural forms: zero, two, few, many
# Expected: zero, one, two, few, many, other
# Found: one, other
#
# locales/pl.json:
# items: missing plural forms: few, many
# Expected: one, few, many, other
# Found: one, other
# Fix: Add all required forms for each language
# See https://unicode.org/cldr/charts/latest/supplemental/language_plural_rules.htmlICU MessageFormat para plurales
La forma recomendada de definir traducciones plurales es ICU MessageFormat. Utiliza una sola cadena con reglas integradas: {count, plural, one {# item} other {# items}'}. ICU es compatible con react-intl, vue-i18n, Angular Transloco, Flutter y la mayoría de los frameworks modernos.
// ICU MessageFormat handles plurals correctly
// It uses CLDR rules internally
// en.json
{
"items": "{count, plural, one {# item} other {# items}}"
}
// ar.json
{
"items": "{count, plural, zero {لا عناصر} one {عنصر واحد} two {عنصران} few {# عناصر} many {# عنصرًا} other {# عنصر}}"
}
// pl.json
{
"items": "{count, plural, one {# element} few {# elementy} many {# elementów} other {# elementu}}"
}
// ICU also handles ordinals:
{
"ranking": "{pos, selectordinal, one {#st} two {#nd} few {#rd} other {#th}}"
}# Validate ICU message syntax
npx i18n-validate --check-icu \
--source locales/en.json \
--targets 'locales/*.json'
# Catches:
# - Missing plural categories for the target language
# - Syntax errors in ICU messages
# - Mismatched variable names
# - Missing "other" (always required)Pruebe i18n Agent ahora
Arrastre y suelte aquí su archivo de traducción
JSON, YAML, PO, XML, CSV, Markdown, Properties
o haga clic para seleccionar
Idiomas de destino