שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
היסטוריית גרסאות
- "Init history"v5.5.1029.6.2025
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתאם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודהעתקת ה-Markdown של המסמך ללוח
Nesting / Sub Content Referencing
How Nesting Works
In Intlayer, nesting is achieved through the nest function, which allows you to reference and reuse content from another dictionary. Instead of duplicating content, you can point to an existing content module by its key.
Setting Up Nesting
To set up nesting in your Intlayer project, you first define the base content that you wish to reuse. Then, in a separate content module, you use the nest function to import that content.
Base Dictionary
Below is an example of a base dictionary to nest in another dictionary:
העתקת הקוד ללוח
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;
Referencing with Nest
Now, create another content module that uses the nest function to reference the above content. You can reference the entire content or a specific nested value:
העתקת הקוד ללוח
import { nest, type Dictionary } from "intlayer";
const myNestingContent = {
key: "key_of_my_second_dictionary",
content: {
// References the entire dictionary:
fullNestedContent: nest("key_of_my_first_dictionary"),
// References a specific nested value:
partialNestedContent: nest(
"key_of_my_first_dictionary",
"subContent.contentNumber"
),
},
} satisfies Dictionary;
export default myNestingContent;
As second parameter, you can specify a path to a nested value within that content. When no path is provided, the entire content of the referenced dictionary is returned.
Using Nesting
To use nested content in a React component, leverage the useIntlayer hook from the react-intlayer package. This hook retrieves the correct content based on the specified key. Here's an example of how to use it:
העתקת הקוד ללוח
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;
To use nested content in Next.js Client Components, retrieve it via the useIntlayer hook. Here's an example:
העתקת הקוד ללוח
"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;
To use nested content in Vue components, retrieve it via the useIntlayer hook. Here's an example:
העתקת הקוד ללוח
To use nested content in Svelte components, retrieve it via the useIntlayer hook. The store is accessed with $. Here's an example:
העתקת הקוד ללוח
To use nested content in Preact components, retrieve it via the useIntlayer hook. Here's an example:
העתקת הקוד ללוח
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;
To use nested content in SolidJS components, retrieve it via the useIntlayer hook. Here's an example:
העתקת הקוד ללוח
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;
To use nested content in Angular components, retrieve it via the useIntlayer hook. Here's an example:
העתקת הקוד ללוח
To use nested content with vanilla-intlayer, retrieve it via the useIntlayer hook. Here's an example:
העתקת הקוד ללוח
import { installIntlayer, useIntlayer } from "vanilla-intlayer";
installIntlayer();
const content = useIntlayer("key_of_my_second_dictionary").onChange(
(newContent) => {
document.getElementById("nested")!.textContent =
newContent.partialNestedContent;
}
);
// Initial render
document.getElementById("nested")!.textContent = content.partialNestedContent;
Additional Resources
For more detailed information on configuration and usage, refer to the following resources:
These resources provide further insights into the setup and usage of Intlayer in different environments and with various frameworks.
