作成:2026-06-12最終更新:2026-06-12
このドキュメントをあなたの好きなAIアシスタントに参照してくださいChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
このページとあなたの好きなAIアシスタントを使ってドキュメントを要約します
バージョン履歴
- "コレクションディクショナリ機能のリリース"v9.0.02026/6/12
このページのコンテンツはAIを使用して翻訳されました。
英語の元のコンテンツの最新バージョンを見るEdit this doc
If you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy
Copy doc Markdown to clipboard
コレクション
コレクション(Collection)は、同じディクショナリキー(key)を共有するものの、それぞれ異なる item インデックスを宣言するコンテンツファイルの集合です。Intlayerはビルド時にこれらを1つの順序付きリストにマージします。
コレクションアイテムの宣言
各ファイルは1つのアイテムを表します。item フィールドは、リスト内での位置を表します(1から開始)。
faq.1.content.ts
コードをコピー
コードをクリップボードにコピー
import { t, type Dictionary } from "intlayer";
const dictionary = {
key: "faq",
item: 1,
content: {
question: t({ en: "What is Intlayer?", fr: "Qu'est-ce qu'Intlayer ?" }),
answer: t({ en: "An i18n toolkit.", fr: "Une boîte à outils i18n." }),
},
} satisfies Dictionary;
export default dictionary;faq.2.content.ts
コードをコピー
コードをクリップボードにコピー
import { t, type Dictionary } from "intlayer";
const dictionary = {
key: "faq",
item: 2,
content: {
question: t({ en: "Is it free?", fr: "Est-ce gratuit ?" }),
answer: t({ en: "Yes, open-source.", fr: "Oui, open-source." }),
},
} satisfies Dictionary;
export default dictionary;コレクションの利用
すべてのアイテム
FAQ.tsx
コードをコピー
コードをクリップボードにコピー
import { useIntlayer } from "react-intlayer";export const FAQ = () => { const items = useIntlayer("faq"); // { question: string; answer: string }[] return ( <ul> {items.map((item, index) => ( <li key={index}> <strong>{item.question}</strong> <p>{item.answer}</p> </li> ))} </ul> );};インデックスによる単一アイテムの取得
tsx
コードをコピー
コードをクリップボードにコピー
const faq2 = useIntlayer("faq", { item: 2 });// → { question: string; answer: string }ロケールを明示した単一アイテムの取得
tsx
コードをコピー
コードをクリップボードにコピー
const faq2Ja = useIntlayer("faq", { item: 2, locale: "ja" });一般的なユースケース
- FAQ(よくある質問)リスト
- 料金プラン
- カルーセル / スライダーの画像・コンテンツ
- ステップ形式のチュートリアル・説明