שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
היסטוריית גרסאות
- "היסטוריה ראשונית"v5.5.1029.6.2025
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתאם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודהעתקת ה-Markdown של המסמך ללוח
קינון / הפניה לתת-תוכן ב-Intlayer
כיצד קינון עובד
ב-Intlayer, קינון מושג באמצעות הפונקציה nest, המאפשרת לך להפנות לתוכן ממילון אחר ולעשות בו שימוש חוזר. במקום לשכפל תוכן, תוכל להצביע על מודול תוכן קיים לפי המפתח שלו.
הגדרת קינון
כדי להגדיר קינון בפרויקט Intlayer שלך, תחילה תגדיר את תוכן הבסיס שבו תרצה לעשות שימוש חוזר. לאחר מכן, במודול תוכן נפרד, תשתמש בפונקציה nest כדי לייבא תוכן זה.
מילון בסיס
להלן דוגמה למילון בסיס להטמעה במילון אחר:
העתקת הקוד ללוח
import { type Dictionary } from "intlayer";
const firstDictionary = {
key: "key_of_my_first_dictionary",
content: {
content: "content",
subContent: {
contentNumber: 0,
contentString: "string",
},
},
} satisfies Dictionary;
export default firstDictionary;
הפניה באמצעות Nest
כעת, צור מודול תוכן נוסף המשתמש בפונקציה nest כדי להפנות לתוכן לעיל. תוכל להפנות לתוכן המלא או לערך מקונן ספציפי:
העתקת הקוד ללוח
import { nest, type Dictionary } from "intlayer";
const myNestingContent = {
key: "key_of_my_second_dictionary",
content: {
// הפניה למילון המלא:
fullNestedContent: nest("key_of_my_first_dictionary"),
// הפניה לערך מקונן ספציפי:
partialNestedContent: nest(
"key_of_my_first_dictionary",
"subContent.contentNumber"
),
},
} satisfies Dictionary;
export default myNestingContent;
כפרמטר שני, תוכל לציין נתיב לערך מקונן בתוך אותו תוכן. כאשר לא מסופק נתיב, מוחזר התוכן המלא של המילון המופנה.
שימוש בקינון
כדי להשתמש בתוכן מקונן ברכיב React, השתמש ב-hook useIntlayer מתוך החבילה react-intlayer. ה-hook שולף את התוכן הנכון על פי המפתח שצוין. להלן דוגמה לשימוש בו:
העתקת הקוד ללוח
import type { FC } from "react";
import { useIntlayer } from "react-intlayer";
const NestComponent: FC = () => {
const { fullNestedContent, partialNestedContent } = useIntlayer(
"key_of_my_second_dictionary"
);
return (
<div>
<p>Full Nested Content: {JSON.stringify(fullNestedContent)}</p>
<p>Partial Nested Value: {partialNestedContent}</p>
</div>
);
};
export default NestComponent;
כדי להשתמש בתוכן מקונן ב-Client Components של Next.js, אחזר אותו באמצעות ה-hook useIntlayer. הנה דוגמה:
העתקת הקוד ללוח
"use client";
import type { FC } from "react";
import { useIntlayer } from "next-intlayer";
const NestComponent: FC = () => {
const { fullNestedContent, partialNestedContent } = useIntlayer(
"key_of_my_second_dictionary"
);
return (
<div>
<p>Full Nested Content: {JSON.stringify(fullNestedContent)}</p>
<p>Partial Nested Value: {partialNestedContent}</p>
</div>
);
};
export default NestComponent;
כדי להשתמש בתוכן מקונן ברכיבי Vue, אחזר אותו באמצעות ה-composable useIntlayer. הנה דוגמה:
העתקת הקוד ללוח
כדי להשתמש בתוכן מקונן ברכיבי Svelte, אחזר אותו באמצעות ה-hook useIntlayer. הגישה ל-store מתבצעת עם $. הנה דוגמה:
העתקת הקוד ללוח
כדי להשתמש בתוכן מקונן ברכיבי Preact, אחזר אותו באמצעות ה-hook useIntlayer. הנה דוגמה:
העתקת הקוד ללוח
import type { FC } from "preact";
import { useIntlayer } from "preact-intlayer";
const NestComponent: FC = () => {
const { fullNestedContent, partialNestedContent } = useIntlayer(
"key_of_my_second_dictionary"
);
return (
<div>
<p>Full Nested Content: {JSON.stringify(fullNestedContent)}</p>
<p>Partial Nested Value: {partialNestedContent}</p>
</div>
);
};
export default NestComponent;
כדי להשתמש בתוכן מקונן ברכיבי SolidJS, אחזר אותו באמצעות ה-hook useIntlayer. הנה דוגמה:
העתקת הקוד ללוח
import type { Component } from "solid-js";
import { useIntlayer } from "solid-intlayer";
const NestComponent: Component = () => {
const { fullNestedContent, partialNestedContent } = useIntlayer(
"key_of_my_second_dictionary"
);
return (
<div>
<p>Full Nested Content: {JSON.stringify(fullNestedContent)}</p>
<p>Partial Nested Value: {partialNestedContent}</p>
</div>
);
};
export default NestComponent;
כדי להשתמש בתוכן מקונן ברכיבי Angular, אחזר אותו באמצעות ה-hook useIntlayer. הנה דוגמה:
העתקת הקוד ללוח
כדי להשתמש בתוכן מקונן עם vanilla-intlayer, אחזר אותו באמצעות ה-hook useIntlayer. הנה דוגמה:
העתקת הקוד ללוח
import { installIntlayer, useIntlayer } from "vanilla-intlayer";
installIntlayer();
const content = useIntlayer("key_of_my_second_dictionary").onChange(
(newContent) => {
document.getElementById("nested")!.textContent =
newContent.partialNestedContent;
}
);
// רינדור ראשוני
document.getElementById("nested")!.textContent = content.partialNestedContent;
משאבים נוספים
למידע מפורט יותר על הגדרות ושימוש, עיין במשאבים הבאים:
משאבים אלה מספקים תובנות נוספות לגבי ההגדרה והשימוש ב-Intlayer בסביבות ובפריימוורקים שונים.
