מחבר:
הפנו את עוזר ה-AI המועדף עליכם למסמך הזהChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
היסטוריית גרסאות
- "Init history"v5.5.1029.6.2025
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתעריכת המסמך הזה
אם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודנוצר:2025-08-23עדכון אחרון:2026-09-27
העתקה
העתקת ה-Markdown של המסמך ללוח
Documentation: getTranslationContent Function in intlayer
Description
The getTranslation function (also aliased as t) retrieves the content corresponding to a specific locale from a set of customizable language content. If the specified locale is not found, it defaults to returning the content for the default locale configured in the project.
For more details on how to declare translations, see the Translation documentation.
Parameters
languageContent: CustomizableLanguageContent<Content>- Description: An object containing translations for various locales. Each key represents a locale, and its value is the corresponding content.
- Type:
CustomizableLanguageContent<Content>Contentcan be any type, defaulting tostring.
locale: Locales- Description: The locale for which content is to be retrieved.
- Type:
Locales
Returns
- Type:
Content - Description: The content corresponding to the specified locale. If the locale is not found, the content of the default locale is returned.
Example Usage
Basic Usage
typescript
העתקת קוד
העתקת הקוד ללוח
import { getTranslationContent, Locales } from "intlayer";
const content = getTranslationContent(
{
en: "Hello",
fr: "Bonjour",
},
Locales.ENGLISH
);
console.log(content); // Output: "Bonjour"
Missing Locale:
typescript
העתקת קוד
העתקת הקוד ללוח
import { getTranslationContent, Locales } from "intlayer";
const content = getTranslationContent(
{
en: "Hello",
fr: "Bonjour",
},
Locales.SPANISH
);
console.log(content); // Output: "Hello" (default locale content)
Using Custom Content Types:
typescript
העתקת קוד
העתקת הקוד ללוח
import { getTranslationContent, Locales } from "intlayer";
const customContent = getTranslationContent<Record<string, string>>(
{
en: { greeting: "Hello" },
fr: { greeting: "Bonjour" },
},
Locales.FRENCH
);
console.log(customContent.greeting); // Output: "Bonjour"
Edge Cases
- Locale Not Found:
- When the
localeis not found in thelanguageContent, the function returns the content for the default locale.
- When the
- Incomplete Language Content:
- If a locale is partially defined, the function does not merge contents. It strictly retrieves the value of the specified locale or falls back to the default.
- TypeScript Enforcement:
- If the locales in
languageContentdo not match the project configuration, TypeScript will enforce all required locales to be defined, ensuring the content is complete and type-safe.
- If the locales in
