作成: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
動的レコード
動的レコード(dynamic record)とは、その同一性が連続するインデックスや名前付きバリアントではなく、meta フィールドで宣言された任意のキー・値ペアの集合によって定義されるコンテンツファイルです。Intlayerはランタイムにこれらのフィールドをセレクターとして使用するため、CMSレコードやユーザー固有のコピー、あるいはビルド時にキーが不明なあらゆるコンテンツを指定することが可能になります。
動적レコードの宣言
product-copy.abc.content.ts
コードをコピー
コードをクリップボードにコピー
import { t, type Dictionary } from "intlayer";
const dictionary = {
key: "product-copy",
meta: {
id: "prod_abc",
userId: "user_123",
},
content: {
name: t({ en: "Widget Pro", fr: "Widget Pro" }),
description: t({ en: "The best widget.", fr: "Le meilleur widget." }),
},
} satisfies Dictionary;
export default dictionary;product-copy.abcd.content.ts
コードをコピー
コードをクリップボードにコピー
import { t, type Dictionary } from "intlayer";
const dictionary = {
key: "product-copy",
meta: {
id: "prod_abcd",
userId: "user_123",
},
content: {
name: t({ en: "Widget Lite", fr: "Widget Lite" }),
description: t({ en: "A lighter option.", fr: "Une option plus légère." }),
},
} satisfies Dictionary;
export default dictionary;動的レコードの消費
セレクターでは、すべての meta フィールドが 必須 です。いずれかのフィールドを省略すると null が返され、TypeScriptのエラーになります。
ProductCopy.tsx
コードをコピー
コードをクリップボードにコピー
import { useIntlayer } from "react-intlayer";
export const ProductCopy = ({
productId,
userId,
}: {
productId: string;
userId: string;
}) => {
const content = useIntlayer("product-copy", { id: productId, userId });
// TypeScriptは、`id` と `userId` の両方が提供されていることを強制します。
if (!content) return null;
return <p>{content.description}</p>;
};ロケールを明示的に指定する場合
tsx
コードをコピー
コードをクリップボードにコピー
const content = useIntlayer("product-copy", { id: "prod_abc", userId: "user_123", locale: "ja",});metaフィールドの不足 — コンパイルエラー
ts
コードをコピー
コードをクリップボードにコピー
// 型エラー: `userId` が不足していますconst content = useIntlayer("product-copy", { id: "prod_abc" });読み込みモード (loading mode)
動的レコードは通常、遅延読み込み(lazy loading)されます。制御するには、ディクショナリで importMode を設定します:
ts
コードをコピー
コードをクリップボードにコピー
const dictionary = {
key: "product-copy",
importMode: "fetch", // または "dynamic"
meta: { id: "prod_abc", userId: "user_123" },
content: { … },
} satisfies Dictionary;
export default dictionary;static、dynamic、fetch モードの詳細については、バンドルの最適化 を参照してください。
一般的なユースケース
- CMSで管理される商品ごとのマーケティングコピー
- ユーザー固有またはアカウント固有のコンテンツ
- 不透明なランタイムIDをキーとするあらゆるコンテンツ