์ด ํ์ด์ง์ ์ํ๋ AI ์ด์์คํดํธ๋ฅผ ์ฌ์ฉํ์ฌ ๋ฌธ์๋ฅผ ์์ฝํฉ๋๋ค
์ด ๋ฌธ์๋ ์ค๋๋์์ต๋๋ค. ๊ธฐ๋ณธ ๋ฒ์ ์ด ๋ค์ ๋ ์ง์ ์ ๋ฐ์ดํธ๋์์ต๋๋ค: 2026๋ 9์ 27์ผ.
์๋ฌธ ๋ฌธ์๋ก ์ด๋๋ฒ์ ๊ธฐ๋ก
- "`useI18n` ํ
๋ฌธ์ ์ด์ ์์ฑ"v6.0.02025. 6. 29.
์ด ํ์ด์ง์ ์ฝํ ์ธ ๋ AI๋ฅผ ์ฌ์ฉํ์ฌ ๋ฒ์ญ๋์์ต๋๋ค.
์์ด ์๋ณธ ๋ด์ฉ์ ์ต์ ๋ฒ์ ์ ๋ณด๊ธฐ์ด ๋ฌธ์๋ฅผ ๊ฐ์ ํ ์์ด๋์ด๊ฐ ์์ผ์๋ฉด GitHub์ ํ ๋ฆฌํ์คํธ๋ฅผ ์ ์ถํ์ฌ ์์ ๋กญ๊ฒ ๊ธฐ์ฌํด ์ฃผ์ธ์.
๋ฌธ์์ ๋ํ GitHub ๋งํฌ๋ฌธ์์ Markdown์ ํด๋ฆฝ๋ณด๋์ ๋ณต์ฌ
React ํตํฉ: useI18n ํ
๋ฌธ์
์ด ์น์
์์๋ React ์ ํ๋ฆฌ์ผ์ด์
๋ด์์ useI18n ํ
์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ํด ์์ธํ ์๋ดํ๋ฉฐ, ํจ์จ์ ์ธ ์ฝํ
์ธ ํ์งํ๋ฅผ ๊ฐ๋ฅํ๊ฒ ํฉ๋๋ค.
React์์ useI18n ๊ฐ์ ธ์ค๊ธฐ
useI18n ํ
์ ๋ค์๊ณผ ๊ฐ์ด ์ํฉ์ ๋ง๊ฒ React ์ ํ๋ฆฌ์ผ์ด์
์ ๊ฐ์ ธ์ ํตํฉํ ์ ์์ต๋๋ค:
ํด๋ผ์ด์ธํธ ์ปดํฌ๋ํธ:
typescript์ฝ๋ ๋ณต์ฌ์ฝ๋๋ฅผ ํด๋ฆฝ๋ณด๋์ ๋ณต์ฌ
์๋ฒ ์ปดํฌ๋ํธ:
๋งค๊ฐ๋ณ์
์ด ํ ์ ๋ ๊ฐ์ ๋งค๊ฐ๋ณ์๋ฅผ ๋ฐ์ต๋๋ค:
namespace: ๋ฒ์ญ ํค์ ๋ฒ์๋ฅผ ์ง์ ํ๋ ์ฌ์ ๋ค์์คํ์ด์ค์ ๋๋ค.locale(์ ํ ์ฌํญ): ์ํ๋ ๋ก์ผ์ผ์ ๋๋ค. ์ง์ ํ์ง ์์ผ๋ฉด ์ปจํ ์คํธ์ ๋ก์ผ์ผ์ด ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ฌ์ฉ๋ฉ๋๋ค.
์ฌ์
๋ชจ๋ ์ฌ์ ํค๋ ํ์ ์์ ์ฑ์ ๋์ด๊ณ ์ค๋ฅ๋ฅผ ๋ฐฉ์งํ๊ธฐ ์ํด ์ฝํ ์ธ ์ ์ธ ํ์ผ ๋ด์ ์ ์ธ๋์ด์ผ ํฉ๋๋ค. ์ค์ ์ง์นจ์ ์ฌ๊ธฐ์์ ํ์ธํ ์ ์์ต๋๋ค.
React์์์ ์ฌ์ฉ ์์
React ์ปดํฌ๋ํธ ๋ด์์ useI18n ํ
์ ์ฌ์ฉํ๋ ์์:
์ฝ๋๋ฅผ ํด๋ฆฝ๋ณด๋์ ๋ณต์ฌ
import type { FC } from "react";
import { ClientComponentExample, ServerComponentExample } from "@components";
import { IntlayerProvider } from "react-intlayer";
import { useI18n } from "react-intlayer/server";
import { Locales } from "intlayer";
const App: FC<{ locale: Locales }> = ({ locale }) => {
const t = useI18n("home-page", locale);
return (
<>
<p>{t("introduction")}</p>
<IntlayerProvider locale={locale}>
<ClientComponentExample />
</IntlayerProvider>
<ServerComponentExample />
</>
);
};
์ฝ๋๋ฅผ ํด๋ฆฝ๋ณด๋์ ๋ณต์ฌ
import type { FC } from "react";
import { ClientComponentExample, ServerComponentExample } from "@components";
import { IntlayerProvider } from "react-intlayer";
import { useI18n, IntlayerServerProvider } from "react.intlayer/server";
import { Locales } from "intlayer";
const App: FC<{ locale: Locales }> = ({ locale }) => {
const t = useI18n("home-page", locale);
return (
<>
<p>{t("introduction")}</p>
<IntlayerProvider locale={locale}>
<ClientComponentExample />
</IntlayerProvider>
<IntlayerServerProvider locale={locale}>
<ServerComponentExample />
</IntlayerServerProvider>
</>
);
};
์ฝ๋๋ฅผ ํด๋ฆฝ๋ณด๋์ ๋ณต์ฌ
import type { FC } from "react";
import { useI18n } from "react-intlayer";
const ComponentExample: FC = () => {
const t = useI18n("component-example");
return (
<div>
<h1>{t("title")}</h1> {/* ์ ๋ชฉ์ ํ์ํฉ๋๋ค */}
<p>{t("description")}</p> {/* ์ค๋ช
์ ํ์ํฉ๋๋ค */}
</div>
);
};
์ฝ๋๋ฅผ ํด๋ฆฝ๋ณด๋์ ๋ณต์ฌ
import { useI18n } from "react-intlayer/server";
const ServerComponentExample = () => {
const t = useI18n("server-component");
return (
<div>
<h1>{t("title")}</h1> {/* ์ ๋ชฉ์ ํ์ํฉ๋๋ค */}
<p>{t("description")}</p> {/* ์ค๋ช
์ ํ์ํฉ๋๋ค */}
</div>
);
};
์์ฑ ์ฒ๋ฆฌ
์์ฑ์ ํ์งํํ ๋๋ ๋ฒ์ญ ๊ฐ์ ์ ์ ํ ์ ๊ทผํด์ผ ํฉ๋๋ค:
์ฝ๋๋ฅผ ํด๋ฆฝ๋ณด๋์ ๋ณต์ฌ
์ถ๊ฐ ์๋ฃ
- Intlayer ๋น์ฃผ์ผ ์๋ํฐ: ๋ณด๋ค ์ง๊ด์ ์ธ ์ฝํ ์ธ ๊ด๋ฆฌ ๊ฒฝํ์ ์ํด ๋น์ฃผ์ผ ์๋ํฐ ๋ฌธ์๋ฅผ ์ฌ๊ธฐ์์ ์ฐธ๊ณ ํ์ธ์.
์ด ์น์
์ React ์ ํ๋ฆฌ์ผ์ด์
์์ useI18n ํ
์ ํตํฉ์ ๊ตฌ์ฒด์ ์ผ๋ก ๋ค๋ฃจ๋ฉฐ, ํ์งํ ๊ณผ์ ์ ๋จ์ํํ๊ณ ๋ค์ํ ๋ก์ผ์ผ ๊ฐ ์ฝํ
์ธ ์ผ๊ด์ฑ์ ๋ณด์ฅํฉ๋๋ค.
