이 페이지와 원하는 AI 어시스턴트를 사용하여 문서를 요약합니다
이 페이지의 콘텐츠는 AI를 사용하여 번역되었습니다.
영어 원본 내용의 최신 버전을 보기이 문서를 개선할 아이디어가 있으시면 GitHub에 풀 리퀘스트를 제출하여 자유롭게 기여해 주세요.
문서에 대한 GitHub 링크문서의 Markdown을 클립보드에 복사
번역
번역 정의하기
intlayer의 t 함수는 여러 언어로 콘텐츠를 선언할 수 있게 해줍니다. 이 함수는 타입 안전성을 보장하며, 번역이 누락된 경우 오류를 발생시켜 특히 TypeScript 환경에서 유용합니다.
다음은 번역이 포함된 콘텐츠를 선언하는 예시입니다.
코드를 클립보드에 복사
import { t, type Dictionary } from "intlayer";
interface Content {
welcomeMessage: string;
}
export default {
key: "multi_lang",
content: {
welcomeMessage: t({
en: "Welcome to our application",
fr: "Bienvenue dans notre application",
es: "Bienvenido a nuestra aplicación",
}),
},
} satisfies Dictionary<Content>;
로케일 구성
적절한 번역 처리를 보장하기 위해 intlayer.config.ts에서 허용되는 로케일을 구성할 수 있습니다. 이 구성은 애플리케이션이 지원하는 언어를 정의할 수 있게 합니다:
코드를 클립보드에 복사
import { Locales, type IntlayerConfig } from "intlayer";
const config: IntlayerConfig = {
internationalization: {
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
},
};
export default config;
로케일 구성
With react-intlayer, you can use translations in React components. Here's an example:
코드를 클립보드에 복사
import type { FC } from "react";
import { useIntlayer } from "react-intlayer";
const MyComponent: FC = () => {
const content = useIntlayer("multi_lang");
return (
<div>
<p>{content.welcomeMessage}</p>
</div>
);
};
export default MyComponent;
This component fetches the corresponding translation based on the current locale set in your application.
With next-intlayer, you can use translations in React Server Components or Client Components. Here's an example in a Client Component:
코드를 클립보드에 복사
"use client";
import type { FC } from "react";
import { useIntlayer } from "next-intlayer";
const MyComponent: FC = () => {
const content = useIntlayer("multi_lang");
return (
<div>
<p>{content.welcomeMessage}</p>
</div>
);
};
export default MyComponent;
With vue-intlayer, you can use translations in Vue components. Here's an example:
코드를 클립보드에 복사
With svelte-intlayer, you can use translations in Svelte components. The hook returns a Svelte store. Here's an example:
코드를 클립보드에 복사
With preact-intlayer, you can use translations in Preact components. Here's an example:
코드를 클립보드에 복사
import type { FC } from "preact";
import { useIntlayer } from "preact-intlayer";
const MyComponent: FC = () => {
const content = useIntlayer("multi_lang");
return (
<div>
<p>{content.welcomeMessage}</p>
</div>
);
};
export default MyComponent;
With solid-intlayer, you can use translations in SolidJS components. Here's an example:
코드를 클립보드에 복사
import type { Component } from "solid-js";
import { useIntlayer } from "solid-intlayer";
const MyComponent: Component = () => {
const content = useIntlayer("multi_lang");
return (
<div>
<p>{content.welcomeMessage}</p>
</div>
);
};
export default MyComponent;
With angular-intlayer, you can use translations in Angular components. Here's an example:
코드를 클립보드에 복사
With vanilla-intlayer, you can use translations by subscribing to content changes. Here's an example:
코드를 클립보드에 복사
import { installIntlayer, useIntlayer } from "vanilla-intlayer";
installIntlayer();
const content = useIntlayer("multi_lang").onChange((newContent) => {
document.getElementById("welcome-message")!.textContent = String(
newContent.welcomeMessage
);
});
// Initial render
document.getElementById("welcome-message")!.textContent = String(
content.welcomeMessage
);
