Skip to main content

CLDR 複数形規則:言語ごとの i18n 複数形カテゴリを検証

英語の複数形式は 2 つ、アラビア語は 6 つ、ロシア語は 4 つです。i18n の設定が「one」と「other」にしか対応していなければ、多くの言語で正しく動作しません。このガイドでは CLDR 複数形規則と、その検証方法を解説します。

1

CLDR 複数形規則とは

Unicode CLDR(Common Locale Data Repository)は、zero、one、two、few、many、other の 6 つの複数形カテゴリを定義します。各言語は、固有の数値規則に従ってこれらの一部を使用します。英語では one(厳密に 1)と other(その他すべて)を使用しますが、多くの言語はさらに複雑です。複数形式を誤ると文法的に不自然なテキストとなり、アプリの品質を損ないます。

The plural problem
// 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.
「other」カテゴリはすべての言語で必須です。他のカテゴリに一致しない場合のフォールバックになります。「one」と「other」だけを定義しても英語では問題ありませんが、世界の言語の 60% 以上で正しく動作しません。
2

6 つの複数形カテゴリ

CLDR が定義する複数形カテゴリは 6 つです。すべての言語が 6 つすべてを使うわけではなく、英語は 2 つ、アラビア語は 6 つすべてを使います。i18n ファイルでは各対象言語に必要なカテゴリを定義しなければなりません。定義しない場合、クラッシュ、キー名の表示、文法的に誤ったテキストにつながります。

CLDR plural categories
// 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)
3

言語別の複数形カテゴリ

一般的な対象言語で必要となる複数形カテゴリの早見表です。翻訳ファイルで複数形式を定義する際に利用できます。

Common mistakes
// 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
4

複数形の自動検証

i18n-validate は、翻訳ファイルの各複数形キーに、対象言語で必要な CLDR カテゴリがすべて定義されているか確認します。ロシア語ファイルに「one」と「other」しかなければ、欠落している「few」と「many」をエラーとして報告します。ユーザーへ影響する前に複数形の問題を検出できるよう、CI で実行してください。

Terminal
# 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
5

複数形の ICU MessageFormat

複数形の翻訳を定義する推奨方法は ICU MessageFormat です。複数形規則を埋め込んだ 1 つの文字列を使用します:{count, plural, one {# item} other {# items}'}。ICU は react-intl、vue-i18n、Angular Transloco、Flutter など、多くの最新 i18n フレームワークでサポートされています。

ICU plural messages
// 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}}"
}
Terminal
# 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)
ICU MessageFormat の # 記号は、書式設定済みの件数へ置き換えられます。複数形式に変数名を直接繰り返さず、# を使用してください。たとえば、count 変数を明示的に繰り返す代わりに「# item / # items」と記述します。

i18n Agent を今すぐ試す

翻訳ファイルをここにドロップ

JSON, YAML, PO, XML, CSV, Markdown, Properties

またはクリックしてファイルを選択

翻訳先言語

登録不要すぐに見積もり

CLDR 複数形規則のよくある質問