--- createdAt: 2026-05-04 updatedAt: 2026-05-04 title: 複数形 description: 多言語ウェブサイトで、ロケールに応じた複数形コンテンツ(CLDRベース)を宣言して使用する方法をご紹介します。このオンラインドキュメントの手順に従って、数分でプロジェクトをセットアップしましょう。 keywords: - 複数形 - 複数化 - CLDR - 国際化 - ドキュメント - Intlayer - Next.js - JavaScript - React slugs: - doc - concept - content - plural history: - version: 8.8.0 date: 2026-05-04 changes: "Init history" --- # 複数形コンテンツ / Intlayerにおける複数形 ## 複数形の仕組み Intlayerでは、複数形コンテンツは `plural` 関数を通じて実現されます。この関数は、CLDRの複数形カテゴリ(`zero`、`one`、`two`、`few`、`many`、`other`)を対応するコンテンツにマッピングします。適切なカテゴリは、プラットフォーム組み込みの [`Intl.PluralRules`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules) APIを使用して、アクティブなロケールとカウント値に基づいて自動的に選択されます。 [`enu`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/dictionary/enumeration.md) は自分で定義した数値範囲に基づいてコンテンツを選択しますが、`plural` は選択をCLDRルールに委ねます。これにより、ロシア語、ポーランド語、アラビア語、ウェールズ語などの複雑な複数化ルールを持つ言語でも、剰余ロジックなどを手書きすることなく拡張可能になります。 ## `plural` と `enu` の使い分け | ユースケース | ヘルパー | | ------------------------------------------------------------------------- | -------- | | ロケールに応じた文法的な複数形(1個のりんご / 2個のりんご / 5個のりんご) | `plural` | | カスタムの数値範囲(`<5`、`>=10`)やCLDR以外のバケット | `enu` | 英語(`one` と `other` のみ)のみを対象とする場合は、どちらでも機能します。`few`、`many`、`two` の区別がある言語の場合は、`plural` を優先してください。 ## 複数形コンテンツのセットアップ Intlayerプロジェクトで複数形コンテンツをセットアップするには、`plural` ヘルパーを使用するコンテンツモジュールを作成します。`other` カテゴリは必須であり、ロケールがより具体的なカテゴリを定義していない場合のフォールバックとして使用されます。 ```typescript fileName="**/*.content.ts" contentDeclarationFormat={["typescript", "esm", "commonjs"]} import { plural, t, type Dictionary } from "intlayer"; const openingsContent = { key: "total_openings", content: { totalOpenings: t({ en: plural({ one: "{{count}} opening", other: "{{count}} openings", }), ja: plural({ other: "{{count}} 件の求人", }), }), }, } satisfies Dictionary; export default openingsContent; ``` ```json fileName="**/*.content.json" contentDeclarationFormat="json" { "$schema": "https://intlayer.org/schema.json", "key": "total_openings", "content": { "totalOpenings": { "nodeType": "translation", "translation": { "en": { "nodeType": "plural", "plural": { "one": "{{count}} opening", "other": "{{count}} openings" } }, "ja": { "nodeType": "plural", "plural": { "other": "{{count}} 件の求人" } } } } } } ``` > サポートされているカテゴリは `zero`、`one`、`two`、`few`、`many`、`other` です。ターゲット言語が使用するカテゴリのみを宣言すればよく、特定のカテゴリが一致しない場合、Intlayerは `other` にフォールバックします。 > > `{{count}}` プレースホルダーは、実行時に渡すカウント値に自動的に置き換えられます。他のプレースホルダーを含めることも可能です(下記の[カスタムプレースホルダー](#custom-placeholders)を参照)。 ## React Intlayer で複数形コンテンツを使用する Reactコンポーネント内で複数形コンテンツを使用するには、`useIntlayer` フック経由で取得し、カウント値を指定して呼び出します。アクティブなロケールとカウント値が組み合わされ、一致するCLDRカテゴリが選択されます。 ```tsx fileName="**/*.tsx" codeFormat={["typescript", "esm"]} import type { FC } from "react"; import { useIntlayer } from "react-intlayer"; const OpeningsComponent: FC<{ count: number }> = ({ count }) => { const { totalOpenings } = useIntlayer("total_openings"); return (
{totalOpenings(count)}