שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
היסטוריית גרסאות
- "עדכון לארכיטקטורת Next.js >= 9.4.0"v9.4.022.8.2026
- "שחרור תכונת הווריאציות (variants)"v9.0.012.6.2026
- "כעת `variant` מקבל מחרוזת או אובייקט, מה שהיה בעבר `meta` / רשומות דינמיות מוצהר כעת כ-object variants"v9.1.026.6.2026
- "וריאציה מצהירה רק על המפתחות שהיא דורסת; וריאציות שלא הוצהרו נופלות לערך ברירת המחדל"v9.1.131.7.2026
- "ספקים (Providers) מקבלים prop בשם `variant` סביבתי; בוררים מקבלים שרשרת העדפות סדורה"v9.1.24.8.2026
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתאם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודהעתקת ה-Markdown של המסמך ללוח
וריאציות (Variants)
וריאציה (variant) היא קבוצה של קובצי תוכן החולקים את אותו מפתח מילון (key), אך כל אחד מהם נושא ערך variant שונה. Intlayer מגיש את הקובץ המתאים בהתבסס על הבורר (selector) המועבר ל-useIntlayer.
ערך ה-variant יכול לקבל שתי צורות:
- מחרוזת: חלופה בודדת בעלת שם (מבחני A/B, באנרים עונתיים, feature flags).
- אובייקט: מבחין מובנה הממוען באמצעות קבוצת שדות (רשומות CMS, ניסוח מותאם משתמש, כל תוכן הממופתח באמצעות מזהה אטום). האובייקט כולו מהווה את הזהות: על הבורר לספק אובייקט זהה כדי לפענח את הרשומה.
צורת האובייקט מחליפה את שדה ה-metaהישן. בכל מקום שבו כתבת בעברmeta: { id, … }, כתוב כעתvariant: { id, … }, ובחר אותו באמצעות{ variant: { id, … } }.
וריאציות בעלות שם (מחרוזת)
כל קובץ מייצג חלופה בעלת שם אחת. השמטת variant (או הגדרתו ל-"default") מסמנת אותו כ-fallback (ברירת המחדל).
העתקת הקוד ללוח
import { t, type Dictionary } from "intlayer";
const dictionary = {
key: "hero-banner",
variant: "default",
content: {
headline: t({
he: "בנו מהר יותר עם Intlayer",
en: "Build faster with Intlayer",
fr: "Développez plus vite avec Intlayer",
}),
cta: t({
he: "להתחיל",
en: "Get started",
fr: "Commencer",
}),
},
} satisfies Dictionary;
export default dictionary;
העתקת הקוד ללוח
import { t, type Dictionary } from "intlayer";
const dictionary = {
key: "hero-banner",
variant: "black_friday",
content: {
headline: t({
he: "50% הנחה, היום בלבד",
en: "50 % off, today only",
fr: "−50 %, aujourd'hui seulement",
}),
cta: t({
he: "קנה עכשיו",
en: "Shop now",
fr: "Acheter maintenant",
}),
},
} satisfies Dictionary;
export default dictionary;
וריאציות חלקיות
וריאציה מצהירה רק על המפתחות שהיא דורסת; השאר עוברים בירושה מרשומת ברירת המחדל.
העתקת הקוד ללוח
import { t, type Dictionary } from "intlayer";
const dictionary = {
key: "hero-banner",
variant: "summer",
content: {
headline: t({
he: "בנו מהר יותר כל הקיץ",
en: "Build faster all summer",
fr: "Développez plus vite tout l'été",
}),
},
} satisfies Dictionary;
export default dictionary;
העתקת הקוד ללוח
לכן עליך להוסיף קובץ variant רק במקומות שבהם הניסוח אכן שונה. מפתח יתפענח ל-null רק כאשר הוא מצהיר על variants אך אין לו רשומת ברירת מחדל.
צריכת וריאציות בעלות שם
וריאציית ברירת מחדל
העתקת הקוד ללוח
import { useIntlayer } from "react-intlayer";
export const Hero = () => {
const { headline, cta } = useIntlayer("hero-banner");
// → וריאציית ברירת מחדל
return (
<section>
<h1>{headline}</h1>
<a>{cta}</a>
</section>
);
};
העתקת הקוד ללוח
import { useIntlayer } from "next-intlayer";
export const Hero = () => {
const { headline, cta } = useIntlayer("hero-banner");
// → וריאציית ברירת מחדל
return (
<section>
<h1>{headline}</h1>
<a>{cta}</a>
</section>
);
};
העתקת הקוד ללוח
<script setup>
import { useIntlayer } from "vue-intlayer";
const { headline, cta } = useIntlayer("hero-banner");
</script>
<template>
<section>
<h1>{{ headline }}</h1>
<a>{{ cta }}</a>
</section>
</template>
העתקת הקוד ללוח
<script lang="ts">
import { useIntlayer } from "svelte-intlayer";
const content = useIntlayer("hero-banner");
</script>
<section>
<h1>{$content.headline}</h1>
<a>{$content.cta}</a>
</section>
העתקת הקוד ללוח
import { useIntlayer } from "preact-intlayer";
export const Hero = () => {
const { headline, cta } = useIntlayer("hero-banner");
// → וריאציית ברירת מחדל
return (
<section>
<h1>{headline}</h1>
<a>{cta}</a>
</section>
);
};
העתקת הקוד ללוח
import { useIntlayer } from "solid-intlayer";
export const Hero = () => {
const content = useIntlayer("hero-banner");
// → וריאציית ברירת מחדל
return (
<section>
<h1>{content().headline}</h1>
<a>{content().cta}</a>
</section>
);
};
העתקת הקוד ללוח
import { Component } from "@angular/core";
import { useIntlayer } from "angular-intlayer";
@Component({
selector: "app-hero",
template: `
<section>
<h1>{{ content().headline }}</h1>
<a>{{ content().cta }}</a>
</section>
`,
})
export class HeroComponent {
content = useIntlayer("hero-banner");
}
העתקת הקוד ללוח
וריאציה בעלת שם
העתקת הקוד ללוח
וריאציה בעלת שם עם שפה מפורשת
העתקת הקוד ללוח
וריאציות אובייקט (מובנות)
וריאציית אובייקט ממקמת תוכן לפי קבוצה שרירותית של זוגות מפתח-ערך המוצהרים בשדה variant, מה שמאפשר למדל רשומות CMS, ניסוח מותאם אישית למשתמש, או כל תוכן שהמפתח שלו הוא מזהה אטום. האובייקט כולו מהווה את הזהות: הבורר חייב לספק אובייקט שווה ערך כדי שהרשומה תפוענח.
העתקת הקוד ללוח
import { t, type Dictionary } from "intlayer";
const dictionary = {
key: "product",
variant: { id: "prod_abc", userId: "user_123" },
content: {
name: t({
he: "וידג'ט פרו",
en: "Widget Pro",
fr: "Widget Pro",
}),
description: t({
he: "הווידג'ט הטוב ביותר.",
en: "The best widget.",
fr: "Le meilleur widget.",
}),
},
} satisfies Dictionary;
export default dictionary;
העתקת הקוד ללוח
import { t, type Dictionary } from "intlayer";
const dictionary = {
key: "product",
variant: { id: "prod_abcd", userId: "user_123" },
content: {
name: t({
he: "וידג'ט לייט",
en: "Widget Lite",
fr: "Widget Lite",
}),
description: t({
he: "אפשרות קלה יותר.",
en: "A lighter option.",
fr: "Une option plus légère.",
}),
},
} satisfies Dictionary;
export default dictionary;
צריכת וריאציות אובייקט
העבר את האובייקט התואם ל-variant. כל שדה שהוצהר במילון חייב להיות מסופק ולהיות שווה; אחרת התוצאה היא null. סדר השדות אינו משנה.
העתקת הקוד ללוח
import { useIntlayer } from "react-intlayer";
export const Product = ({
productId,
userId,
}: {
productId: string;
userId: string;
}) => {
const content = useIntlayer("product", {
variant: { id: productId, userId },
});
if (!content) return null;
return <p>{content.description}</p>;
};
העתקת הקוד ללוח
import { useIntlayer } from "next-intlayer";
export const Product = ({
productId,
userId,
}: {
productId: string;
userId: string;
}) => {
const content = useIntlayer("product", {
variant: { id: productId, userId },
});
if (!content) return null;
return <p>{content.description}</p>;
};
העתקת הקוד ללוח
<script setup>
import { useIntlayer } from "vue-intlayer";
const props = defineProps({
productId: String,
userId: String,
});
const content = useIntlayer("product", {
variant: { id: props.productId, userId: props.userId },
});
</script>
<template>
<p v-if="content">{{ content.description }}</p>
</template>
העתקת הקוד ללוח
<script lang="ts">
import { useIntlayer } from "svelte-intlayer";
export let productId: string;
export let userId: string;
const content = useIntlayer("product", {
variant: { id: productId, userId },
});
</script>
{#if $content}
<p>{$content.description}</p>
{/if}
העתקת הקוד ללוח
import { useIntlayer } from "preact-intlayer";
export const Product = ({
productId,
userId,
}: {
productId: string;
userId: string;
}) => {
const content = useIntlayer("product", {
variant: { id: productId, userId },
});
if (!content) return null;
return <p>{content.description}</p>;
};
העתקת הקוד ללוח
import { useIntlayer } from "solid-intlayer";
export const Product = (props: {
productId: string;
userId: string;
}) => {
const content = useIntlayer("product", {
variant: { id: props.productId, userId: props.userId },
});
return (
<>
{content() && <p>{content().description}</p>}
</>
);
};
העתקת הקוד ללוח
import { Component, Input, OnInit } from "@angular/core";
import { useIntlayer } from "angular-intlayer";
@Component({
selector: "app-product",
template: `
@if (content()) {
<p>{{ content().description }}</p>
}
`,
})
export class ProductComponent implements OnInit {
@Input() productId!: string;
@Input() userId!: string;
content: any;
ngOnInit() {
this.content = useIntlayer("product", {
variant: { id: this.productId, userId: this.userId },
});
}
}
העתקת הקוד ללוח
עם שפה מפורשת
העתקת הקוד ללוח
שדה חסר, ללא התאמה
העתקת הקוד ללוח
וריאציה סביבתית (Ambient variant)
ממדי וריאציה מסוימים קבועים עבור סשן שלם, ה-tenant, סוג בית הספר, או רמת התוכנית (plan tier). הם מפוענחים פעם אחת, ואף רכיב אינו צריך להעביר אותם ידנית.
אל תעטוף אתuseIntlayerב-hook משלך כדי להזריק אותם. אופטימיזציית זמן הבנייה משכתבת אך ורק קריאות מילוליות שלuseIntlayer("key")המיובאות ישירות מחבילת הפריימוורק, כך ששום דבר מאחורי עטיפה אינו נכלל ב-bundle בצורה ממוטבת.
הצהר על ה-variant פעם אחת ב-provider במקום זאת, בדיוק כמו locale:
העתקת הקוד ללוח
import { IntlayerProvider } from "react-intlayer";
export const App = ({ locale, schoolType }) => (
<IntlayerProvider locale={locale} variant={schoolType}>
<Hero />
</IntlayerProvider>
);
העתקת הקוד ללוח
import { IntlayerProvider } from "next-intlayer/server";
export default async function Layout({ children, params }) {
const { locale } = await params;
const schoolType = await getSchoolType();
return (
<IntlayerProvider locale={locale} variant={schoolType}>
{children}
</IntlayerProvider>
);
}
העתקת הקוד ללוח
import { IntlayerServerProvider } from "next-intlayer/server";
import { IntlayerClientProvider } from "next-intlayer";
export default async function Layout({ children, params }) {
const { locale } = await params;
const schoolType = await getSchoolType();
return (
<IntlayerServerProvider locale={locale} variant={schoolType}>
<IntlayerClientProvider locale={locale} variant={schoolType}>
{children}
</IntlayerClientProvider>
</IntlayerServerProvider>
);
}
העתקת הקוד ללוח
import { createApp } from "vue";
import { installIntlayer } from "vue-intlayer";
import App from "./App.vue";
const app = createApp(App);
installIntlayer(app, { locale: "en", variant: schoolType });
app.mount("#app");
העתקת הקוד ללוח
<script lang="ts">
import { setupIntlayer } from "svelte-intlayer";
export let schoolType: string;
setupIntlayer("en", schoolType);
</script>
<slot />
העתקת הקוד ללוח
import { IntlayerProvider } from "preact-intlayer";
export const App = ({ locale, schoolType }) => (
<IntlayerProvider locale={locale} variant={schoolType}>
<Hero />
</IntlayerProvider>
);
העתקת הקוד ללוח
import { IntlayerProvider } from "solid-intlayer";
export const App = (props) => (
<IntlayerProvider locale={props.locale} variant={props.schoolType}>
<Hero />
</IntlayerProvider>
);
העתקת הקוד ללוח
import { ApplicationConfig } from "@angular/core";
import { provideIntlayer } from "angular-intlayer";
export const appConfig: ApplicationConfig = {
providers: [provideIntlayer("en", true, schoolType)],
};
העתקת הקוד ללוח
כל קריאת מילון מתחת ל-provider מתפענחת כעת מול אותה וריאציה, ובורר באתר הקריאה (call-site) תמיד מנצח:
העתקת הקוד ללוח
צורות שימוש (Forms)
ה-prop variant מקבל שלוש צורות:
פתיחת הטבלה בחלון כדי לראות את כל תוכן הנתונים בבירור
| צורה | משמעות |
|---|---|
variant="school1" | וריאציה אחת בעלת שם עבור כל מפתח |
variant={["school1", "default"]} | שרשרת העדפות סדורה |
variant={{ "hero-banner": "school1", default: "base" }} | וריאציה אחת לכל מפתח מילון |
שרשרת העדפות
שרשרת נבדקת משמאל לימין מול הרשומות שכל מפתח מצהיר עליהן, והרשומה המוצהרת הראשונה מנצחת. כאשר אף אחת מהן אינה מוצהרת, נעשה שימוש ברשומת ברירת המחדל המשתמעת, בדיוק כמו עבור ערך בודד.
העתקת הקוד ללוח
לפיכך, ["black_friday", "summer"] נקרא כ"בלאק פריידי אם למפתח זה יש כזה, אחרת קיץ, אחרת ברירת מחדל". שרשראות מתקבלות גם באתר הקריאה:
העתקת הקוד ללוח
שים לב שזוהי תמונת ראי של המערך המתקבל על ידי שדה ה-variant בקובץ תוכן: שם מערך מצהיר על רשומה אחת לכל אלמנט, כאן הוא צורך אותן בסדר עדיפות.
מפה לפי מפתח (Per-key map)
פנה לכל מפתח מילון בנפרד. רשומת default השמורה מכסה כל מפתח שאינו מצוין ברשימה:
העתקת הקוד ללוח
ב-provider, אובייקט רגיל נקרא תמיד כמפה לפי מפתח, ולעולם לא כ-object variant (שכן השניים זהים מבנית). כדי להגדיר object variant באופן גלובלי, קנן אותו תחת רשומה: variant={{ default: { id: "prod_abc" } }}.
מכיוון שמפתחות המפה נבדקים מול מפתחות המילון שהצהרת עליהם, שגיאת כתיב (או object variant שנכתב ישירות, כגון variant={{ id: "prod_abc" }}) מהווה שגיאת זמן הידור (compile-time error).
מצב טעינה (Loading mode)
וריאציות אובייקט נטענות לעתים קרובות באופן עצל (lazy). הגדר importMode במילון כדי לשלוט בכך:
העתקת הקוד ללוח
const dictionary = {
key: "product",
importMode: "fetch", // או "dynamic"
variant: { id: "prod_abc", userId: "user_123" },
content: {/* … */},
} satisfies Dictionary;
export default dictionary;
עיין באופטימיזציית bundle לפרטים על מצבי static, dynamic ו-fetch.
תרחישי שימוש נפוצים
- מבחני ניסוח A/B המונעים על ידי מפתח ניסוי
- באנרים עונתיים או פרסומיים
- הודעות מבוססות feature flags
- קמפיינים שיווקיים מותאמי שפה
- ניסוח שיווקי לכל מוצר המנוהל ב-CMS
- תוכן ספציפי למשתמש או לחשבון
- כל תוכן הממופתח באמצעות מזהה אטום בזמן ריצה
