Creation:2024-08-11Last update:2025-06-29
このドキュメントをあなたの好きなAIアシスタントに参照してくださいChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
このページとあなたの好きなAIアシスタントを使ってドキュメントを要約します
このページのコンテンツは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
ドキュメント: intlayer の getTranslationContent 関数
説明
getTranslationContent 関数は、カスタマイズ可能な言語コンテンツのセットから特定のロケールに対応するコンテンツを取得します。指定されたロケールが見つからない場合は、プロジェクトで設定されたデフォルトのロケールのコンテンツを返します。
パラメーター
languageContent: CustomizableLanguageContent<Content>- 説明: 複数のロケールの翻訳を含むオブジェクトです。各キーはロケールを表し、その値が対応するコンテンツです。
- 型:
CustomizableLanguageContent<Content>Contentは任意の型で、デフォルトはstringです。
locale: Locales- 説明: コンテンツを取得する対象のロケールです。
- 型:
Locales
戻り値
- 型:
Content - 説明: 指定されたロケールに対応するコンテンツです。ロケールが見つからない場合は、デフォルトのロケールのコンテンツが返されます。
使用例
基本的な使用例
typescript
コードをコピー
コードをクリップボードにコピー
import { getTranslationContent, Locales } from "intlayer";
const content = getTranslationContent(
{
en: "Hello",
fr: "Bonjour",
},
Locales.ENGLISH
);
console.log(content); // 出力: "Bonjour"ロケールが見つからない場合:
typescript
コードをコピー
コードをクリップボードにコピー
import { getTranslationContent, Locales } from "intlayer";
const content = getTranslationContent(
{
en: "Hello",
fr: "Bonjour",
},
Locales.SPANISH
);
console.log(content); // 出力: "Hello" (デフォルトロケールの内容)カスタムコンテンツタイプの使用:
typescript
コードをコピー
コードをクリップボードにコピー
import { getTranslationContent, Locales } from "intlayer";
const customContent = getTranslationContent<Record<string, string>>(
{
en: { greeting: "Hello" },
fr: { greeting: "Bonjour" },
},
Locales.FRENCH
);
console.log(customContent.greeting); // 出力: "Bonjour"エッジケース
- ロケールが見つからない場合:
localeがlanguageContentに見つからない場合、関数はデフォルトのロケールのコンテンツを返します。
- 不完全な言語コンテンツ:
- ロケールが部分的に定義されている場合、関数はコンテンツをマージしません。指定されたロケールの値を厳密に取得するか、デフォルトにフォールバックします。
- TypeScriptの強制:
languageContent内のロケールがプロジェクトの設定と一致しない場合、TypeScriptはすべての必須ロケールが定義されていることを強制し、コンテンツが完全かつ型安全であることを保証します。