이 페이지와 원하는 AI 어시스턴트를 사용하여 문서를 요약합니다
이 페이지의 콘텐츠는 AI를 사용하여 번역되었습니다.
영어 원본 내용의 최신 버전을 보기이 문서를 개선할 아이디어가 있으시면 GitHub에 풀 리퀘스트를 제출하여 자유롭게 기여해 주세요.
문서에 대한 GitHub 링크문서의 Markdown을 클립보드에 복사
중첩 / 하위 콘텐츠 참조
중첩 작동 방식
Intlayer에서 중첩은 nest 함수를 통해 이루어지며, 이를 통해 다른 사전의 콘텐츠를 참조하고 재사용할 수 있습니다. 콘텐츠를 중복 작성하는 대신, 기존 콘텐츠 모듈의 키를 통해 해당 콘텐츠를 가리킬 수 있습니다.
중첩 설정
Intlayer 프로젝트에서 중첩을 설정하려면 먼저 재사용하려는 기본 콘텐츠를 정의합니다. 그런 다음 별도의 콘텐츠 모듈에서 nest 함수를 사용하여 해당 콘텐츠를 가져옵니다.
기본 Dictionary
다른 dictionary에 중첩할 기본 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;
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;
두 번째 파라미터로는 해당 콘텐츠 내의 중첩된 값으로의 경로를 지정할 수 있습니다. 경로가 제공되지 않으면 참조된 딕셔너리의 전체 콘텐츠가 반환됩니다.
중첩 설정
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;
추가 자료
구성 및 사용에 대한 자세한 정보는 다음 리소스를 참조하세요:
이 리소스들은 다양한 환경 및 프레임워크에서 Intlayer를 설정하고 사용하는 방법에 대한 추가적인 통찰을 제공합니다.
