
CLDR बहुवचन नियम: सभी भाषाओं में i18n बहुवचन श्रेणियाँ सत्यापित करें
अंग्रेज़ी में बहुवचन के 2 रूप हैं। अरबी में 6 और रूसी में 4 हैं। यदि आपका i18n सेटअप केवल 'one' और 'other' को संभालता है, तो आपका ऐप अधिकांश भाषाओं में ठीक से काम नहीं करेगा। इस गाइड में CLDR बहुवचन नियमों और उनके सत्यापन का तरीका समझाया गया है।
CLDR बहुवचन नियम क्या हैं?
Unicode CLDR (Common Locale Data Repository) बहुवचन की छह श्रेणियाँ निर्धारित करता है: zero, one, two, few, many और other। हर भाषा विशिष्ट संख्यात्मक नियमों के साथ इन श्रेणियों के किसी उपसमूह का उपयोग करती है। अंग्रेज़ी में one (ठीक 1) और other (बाकी सभी) का उपयोग होता है। लेकिन अधिकांश भाषाएँ अधिक जटिल हैं—और बहुवचन रूपों में गलती होने से व्याकरण की दृष्टि से गलत टेक्स्ट दिखाई देता है, जिससे आपका ऐप गैर-पेशेवर लगता है।
// 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.बहुवचन की छह श्रेणियाँ
CLDR बहुवचन की ठीक छह श्रेणियाँ निर्धारित करता है। हर भाषा सभी छह श्रेणियों का उपयोग नहीं करती—अंग्रेज़ी केवल दो का और अरबी सभी छह का उपयोग करती है। आपकी i18n फ़ाइलों में हर लक्षित भाषा के लिए आवश्यक श्रेणियाँ निर्धारित होनी चाहिए, अन्यथा यूज़र को क्रैश, रॉ कुंजियाँ या व्याकरण की दृष्टि से गलत टेक्स्ट दिखाई दे सकता है।
// 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)भाषा के अनुसार बहुवचन श्रेणियाँ
सामान्य लक्षित भाषाओं के लिए आवश्यक बहुवचन श्रेणियों का त्वरित संदर्भ। अपनी अनुवाद फ़ाइलों में बहुवचन रूप निर्धारित करते समय इसका उपयोग करें।
// 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 translatedस्वचालित बहुवचन सत्यापन
i18n-validate जाँचता है कि आपकी अनुवाद फ़ाइलों की हर बहुवचन कुंजी में लक्षित भाषा के लिए आवश्यक सभी CLDR श्रेणियाँ निर्धारित हैं। यदि आपकी रूसी फ़ाइल में केवल 'one' और 'other' रूप हैं, तो टूल अनुपलब्ध 'few' और 'many' श्रेणियों को त्रुटियों के रूप में चिह्नित करता है। बहुवचन संबंधी समस्याएँ यूज़र तक पहुँचने से पहले पकड़ने के लिए इसे CI में चलाएँ।
# 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.htmlबहुवचन के लिए ICU MessageFormat
बहुवचन अनुवाद निर्धारित करने का अनुशंसित तरीका ICU MessageFormat है। इसमें एम्बेड किए गए बहुवचन नियमों वाली एक ही स्ट्रिंग का उपयोग होता है: {count, plural, one {# item} other {# items}'}। ICU को react-intl, vue-i18n, Angular Transloco, Flutter और अधिकांश आधुनिक i18n फ़्रेमवर्क सपोर्ट करते हैं।
// 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)i18n Agent अभी आज़माएँ
अपनी अनुवाद फ़ाइल यहाँ छोड़ें
JSON, YAML, PO, XML, CSV, Markdown, Properties
या ब्राउज़ करने के लिए क्लिक करें
लक्षित भाषाएँ