์ฝ˜ํ…์ธ  ๋Œ€ํ‘œ ์ด๋ฏธ์ง€ - ๐ŸŒ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋กœ ์„ธ๊ณ„๋ฅผ ์ •๋ณตํ•˜์ž! ๊ตญ์ œํ™”์™€ i18n ์™„๋ฒฝ ๊ฐ€์ด๋“œ

๐ŸŒ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋กœ ์„ธ๊ณ„๋ฅผ ์ •๋ณตํ•˜์ž! ๊ตญ์ œํ™”์™€ i18n ์™„๋ฒฝ ๊ฐ€์ด๋“œ

๋‹ค๊ตญ์–ด ํƒ€์ž… ์‹œ์Šคํ…œ์œผ๋กœ ๊ธ€๋กœ๋ฒŒ ์„œ๋น„์Šค ๋งŒ๋“ค๊ธฐ

์•ˆ๋…•! ์˜ค๋Š˜์€ ์ •๋ง ์žฌ๋ฏธ์žˆ๋Š” ์ฃผ์ œ๋ฅผ ๊ฐ€์ง€๊ณ  ์™”์–ด. ๋ฐ”๋กœ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋กœ ๋‹ค๊ตญ์–ด ์ง€์›ํ•˜๊ธฐ์•ผ! ๐Ÿš€

์š”์ฆ˜ ์›น ์„œ๋น„์Šค๋ฅผ ๋งŒ๋“ค๋‹ค ๋ณด๋ฉด ํ•œ๊ตญ์–ด๋งŒ ์ง€์›ํ•˜๋Š” ๊ฑด ๋ญ”๊ฐ€ ์•„์‰ฝ์ž–์•„? ๋ฏธ๊ตญ ์นœ๊ตฌ๋“ค๋„ ์“ฐ๊ณ , ์ผ๋ณธ ์นœ๊ตฌ๋“ค๋„ ์“ฐ๊ณ , ํ”„๋ž‘์Šค ์นœ๊ตฌ๋“ค๋„ ์“ธ ์ˆ˜ ์žˆ๊ฒŒ ๋งŒ๋“ค๊ณ  ์‹ถ์€๋ฐ... ๊ทธ๋Ÿฐ๋ฐ ๋ง‰์ƒ ์‹œ์ž‘ํ•˜๋ ค๋‹ˆ๊นŒ "์–ด? ์ด๊ฑฐ ์–ด๋–ป๊ฒŒ ํ•˜์ง€?" ์‹ถ์€ ๊ฑฐ์•ผ. ํŠนํžˆ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋ฅผ ์“ฐ๋ฉด์„œ ํƒ€์ž… ์•ˆ์ •์„ฑ๊นŒ์ง€ ์ฑ™๊ธฐ๋ ค๋ฉด ๋จธ๋ฆฌ๊ฐ€ ์ข€ ๋ณต์žกํ•ด์ง€๊ฑฐ๋“ . ๐Ÿ˜…

๊ทธ๋ž˜์„œ ์˜ค๋Š˜์€ ์นœ๊ตฌํ•œํ…Œ ์„ค๋ช…ํ•˜๋“ฏ์ด ํŽธํ•˜๊ฒŒ, ๊ทธ๋Ÿฌ๋ฉด์„œ๋„ ์ œ๋Œ€๋กœ ์•Œ๋ ค์ค„๊ฒŒ. ๊ตญ์ œํ™”(i18n)๊ฐ€ ๋ญ”์ง€๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ, ์‹ค์ œ๋กœ ์–ด๋–ป๊ฒŒ ๊ตฌํ˜„ํ•˜๋Š”์ง€, ํƒ€์ž… ์‹œ์Šคํ…œ์€ ์–ด๋–ป๊ฒŒ ํ™œ์šฉํ•˜๋Š”์ง€๊นŒ์ง€ ์‹น ๋‹ค ๋‹ค๋ค„๋ณผ ๊ฑฐ์•ผ!

๐Ÿค” i18n์ด ๋ญ๊ธธ๋ž˜?

๋จผ์ € i18n์ด๋ผ๋Š” ์šฉ์–ด๋ถ€ํ„ฐ ์•Œ์•„๋ณด์ž. ์ด๊ฑฐ ์ฒ˜์Œ ๋ณด๋ฉด "์•„์ด์ผํŒ”์—”? ์ด๊ฒŒ ๋ญ์•ผ?" ์‹ถ์„ ๊ฑฐ์•ผ. ์‚ฌ์‹ค ์ด๊ฑด internationalization์˜ ์ค„์ž„๋ง์ด์•ผ. i๋กœ ์‹œ์ž‘ํ•ด์„œ n์œผ๋กœ ๋๋‚˜๋Š”๋ฐ, ๊ทธ ์‚ฌ์ด์— ๊ธ€์ž๊ฐ€ 18๊ฐœ ์žˆ์–ด์„œ i18n์ด๋ผ๊ณ  ๋ถ€๋ฅด๋Š” ๊ฑฐ์ง€. ํ”„๋กœ๊ทธ๋ž˜๋จธ๋“ค ํŠน์œ ์˜ ๊ฒŒ์œผ๋ฆ„(?)์ด ๋งŒ๋“ค์–ด๋‚ธ ์•ฝ์–ด์•ผ. ๐Ÿ˜„

๐Ÿ’ก ๊ตญ์ œํ™” vs ์ง€์—ญํ™” ๊ตญ์ œํ™”(i18n): ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ์—ฌ๋Ÿฌ ์–ธ์–ด์™€ ์ง€์—ญ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค๊ณ„ํ•˜๋Š” ๊ณผ์ •
์ง€์—ญํ™”(l10n): ํŠน์ • ์–ธ์–ด์™€ ์ง€์—ญ์— ๋งž๊ฒŒ ์‹ค์ œ๋กœ ๋ฒˆ์—ญํ•˜๊ณ  ์ ์šฉํ•˜๋Š” ๊ณผ์ •

์‰ฝ๊ฒŒ ๋งํ•˜๋ฉด, ๊ตญ์ œํ™”๋Š” "๋‹ค๊ตญ์–ด ์ง€์›์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ๊ตฌ์กฐ๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ"์ด๊ณ , ์ง€์—ญํ™”๋Š” "์‹ค์ œ๋กœ ํ•œ๊ตญ์–ด, ์˜์–ด, ์ผ๋ณธ์–ด ๋“ฑ์œผ๋กœ ๋ฒˆ์—ญํ•˜๋Š” ๊ฒƒ"์ด์•ผ. ์ง‘์„ ์ง€์„ ๋•Œ ๊ตญ์ œํ™”๋Š” ์„ค๊ณ„๋„๋ฅผ ๊ทธ๋ฆฌ๋Š” ๊ฑฐ๊ณ , ์ง€์—ญํ™”๋Š” ์‹ค์ œ๋กœ ๋ฒฝ๋Œ์„ ์Œ“๋Š” ๊ฑฐ๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋ผ!

๐Ÿ—๏ธ i18n ๊ตฌ์กฐ ์„ค๊ณ„ ๐ŸŒ l10n ์‹ค์ œ ๋ฒˆ์—ญ ํ•œ๊ตญ์–ด English ๆ—ฅๆœฌ่ชž ๊ตญ์ œํ™” ํ”„๋กœ์„ธ์Šค

๐ŸŽฏ ์™œ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์—์„œ i18n์ด ์ค‘์š”ํ• ๊นŒ?

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ ๋‹ค๊ตญ์–ด ์ง€์›์„ ๊ตฌํ˜„ํ•˜๋ฉด ์ด๋Ÿฐ ์ƒํ™ฉ์ด ์ƒ๊ฒจ:

// ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ ํ”ํžˆ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ
const greeting = t('welcom'); // ์˜คํƒ€! welcome์ด ์•„๋‹ˆ๋ผ welcom
console.log(greeting); // undefined ๋˜๋Š” ์—๋Ÿฌ

๋ณด์ด์ง€? ํ‚ค ์ด๋ฆ„์„ ์ž˜๋ชป ์“ฐ๋ฉด ๋Ÿฐํƒ€์ž„์—์„œ์•ผ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•ด. ๊ทธ๊ฒƒ๋„ ์‚ฌ์šฉ์ž๊ฐ€ ์‹ค์ œ๋กœ ๊ทธ ํŽ˜์ด์ง€๋ฅผ ์—ด์—ˆ์„ ๋•Œ! ๐Ÿ˜ฑ

ํ•˜์ง€๋งŒ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ œ๋Œ€๋กœ ํ™œ์šฉํ•˜๋ฉด:

// ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์˜ ๋งˆ๋ฒ• โœจ
const greeting = t('welcom'); // ๋นจ๊ฐ„ ์ค„! IDE๊ฐ€ ๋ฐ”๋กœ ์•Œ๋ ค์คŒ
// Error: Argument of type '"welcom"' is not assignable to parameter of type '"welcome" | "goodbye"'
๐ŸŽ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์˜ ์„ ๋ฌผ ํƒ€์ž… ์‹œ์Šคํ…œ์„ ํ™œ์šฉํ•˜๋ฉด ๋ฒˆ์—ญ ํ‚ค์˜ ์˜คํƒ€, ๋ˆ„๋ฝ๋œ ๋ฒˆ์—ญ, ์ž˜๋ชป๋œ ๋งค๊ฐœ๋ณ€์ˆ˜ ๋“ฑ์„ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ์ˆœ๊ฐ„ ๋ฐ”๋กœ ์žก์„ ์ˆ˜ ์žˆ์–ด. ์ด๊ฒŒ ์–ผ๋งˆ๋‚˜ ํฐ ์žฅ์ ์ธ์ง€ ๋ชฐ๋ผ!

ํŠนํžˆ ํ”„๋กœ์ ํŠธ๊ฐ€ ์ปค์ง€๊ณ  ๋ฒˆ์—ญ ํ‚ค๊ฐ€ ์ˆ˜๋ฐฑ ๊ฐœ๊ฐ€ ๋˜๋ฉด, ์ด๋Ÿฐ ํƒ€์ž… ์•ˆ์ •์„ฑ์€ ์ •๋ง ์ƒ๋ช…์ค„์ด ๋ผ. ์‹ค์ œ๋กœ ์žฌ๋Šฅ๋„ท ๊ฐ™์€ ํ”Œ๋žซํผ์—์„œ๋„ ๋‹ค๊ตญ์–ด ์ง€์›์„ ํ•  ๋•Œ ์ด๋Ÿฐ ํƒ€์ž… ์‹œ์Šคํ…œ์ด ์–ผ๋งˆ๋‚˜ ์ค‘์š”ํ•œ์ง€ ์ฒด๊ฐํ•  ์ˆ˜ ์žˆ์„ ๊ฑฐ์•ผ.

๐Ÿ“š ์ฃผ์š” i18n ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ดํŽด๋ณด๊ธฐ

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” i18n ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์—ฌ๋Ÿฌ ๊ฐ€์ง€๊ฐ€ ์žˆ์–ด. ๊ฐ๊ฐ์˜ ํŠน์ง•์„ ์•Œ์•„๋ณด์ž!

1๏ธโƒฃ react-i18next

React ์ƒํƒœ๊ณ„์—์„œ ๊ฐ€์žฅ ์ธ๊ธฐ ์žˆ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์•ผ. i18next๋ฅผ React์— ๋งž๊ฒŒ ๋ž˜ํ•‘ํ•œ ๊ฑฐ์ง€.

โœจ ์ฃผ์š” ํŠน์ง•
๐Ÿ”„ ๋™์  ๋กœ๋”ฉ ๐ŸŽฃ React Hooks ์ง€์› ๐Ÿ“ฆ ํ”Œ๋Ÿฌ๊ทธ์ธ ์ƒํƒœ๊ณ„ ๐ŸŒ ๋„ค์ž„์ŠคํŽ˜์ด์Šค ์ง€์›
// react-i18next ๊ธฐ๋ณธ ์„ค์ •
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';

i18n
  .use(initReactI18next)
  .init({
    resources: {
      ko: {
        translation: {
          welcome: "ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค!",
          goodbye: "์•ˆ๋…•ํžˆ ๊ฐ€์„ธ์š”!"
        }
      },
      en: {
        translation: {
          welcome: "Welcome!",
          goodbye: "Goodbye!"
        }
      }
    },
    lng: 'ko',
    fallbackLng: 'en',
    interpolation: {
      escapeValue: false
    }
  });

export default i18n;

์‚ฌ์šฉํ•  ๋•Œ๋Š” ์ด๋ ‡๊ฒŒ ๊ฐ„๋‹จํ•ด:

import { useTranslation } from 'react-i18next';

function MyComponent() {
  const { t, i18n } = useTranslation();
  
  const changeLanguage = (lng: string) => {
    i18n.changeLanguage(lng);
  };
  
  return (
    <div>
      <h1>{t('welcome')}</h1>
      <button onClick={() => changeLanguage('en')}>English</button>
      <button onClick={() => changeLanguage('ko')}>ํ•œ๊ตญ์–ด</button>
    </div>
  );
}

2๏ธโƒฃ next-i18next

Next.js๋ฅผ ์“ด๋‹ค๋ฉด ์ด๊ฒŒ ์ตœ๊ณ ์•ผ! Next.js์˜ ๋ผ์šฐํŒ… ์‹œ์Šคํ…œ๊ณผ ์™„๋ฒฝํ•˜๊ฒŒ ํ†ตํ•ฉ๋ผ ์žˆ์–ด.

๐Ÿš€ Next.js ํŠนํ™” ๊ธฐ๋Šฅ โ€ข ์ž๋™ ์–ธ์–ด ๊ฐ์ง€ ๋ฐ ๋ฆฌ๋‹ค์ด๋ ‰์…˜
โ€ข SSR/SSG ์™„๋ฒฝ ์ง€์›
โ€ข ํŒŒ์ผ ๊ธฐ๋ฐ˜ ๋ผ์šฐํŒ…๊ณผ ํ†ตํ•ฉ
โ€ข ์ž๋™ ๋ฒˆ์—ญ ํŒŒ์ผ ๋กœ๋”ฉ
// next-i18next.config.js
module.exports = {
  i18n: {
    defaultLocale: 'ko',
    locales: ['ko', 'en', 'ja'],
    localeDetection: true,
  },
  localePath: './public/locales',
};

// pages/_app.tsx
import { appWithTranslation } from 'next-i18next';

function MyApp({ Component, pageProps }) {
  return <Component {...pageProps} />;
}

export default appWithTranslation(MyApp);

3๏ธโƒฃ vue-i18n

Vue.js ์‚ฌ์šฉ์ž๋ผ๋ฉด ๋‹น์—ฐํžˆ ์ด๊ฑฐ์ง€! Vue 3์™€ Composition API๋ฅผ ์™„๋ฒฝํ•˜๊ฒŒ ์ง€์›ํ•ด.

// Vue 3 + TypeScript
import { createI18n } from 'vue-i18n';

const i18n = createI18n({
  legacy: false,
  locale: 'ko',
  fallbackLocale: 'en',
  messages: {
    ko: {
      message: {
        hello: '์•ˆ๋…•ํ•˜์„ธ์š”!'
      }
    },
    en: {
      message: {
        hello: 'Hello!'
      }
    }
  }
});

// ์ปดํฌ๋„ŒํŠธ์—์„œ ์‚ฌ์šฉ
import { useI18n } from 'vue-i18n';

export default {
  setup() {
    const { t, locale } = useI18n();
    
    return { t, locale };
  }
};

4๏ธโƒฃ typesafe-i18n

์ด๊ฑด ์ง„์งœ ํƒ€์ž… ์•ˆ์ •์„ฑ์— ๋ฏธ์นœ(?) ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์•ผ. 100% ํƒ€์ž… ์„ธ์ดํ”„๋ฅผ ๋ณด์žฅํ•ด!

๐Ÿ›ก๏ธ ์™„๋ฒฝํ•œ ํƒ€์ž… ์•ˆ์ •์„ฑ typesafe-i18n์€ ๋ฒˆ์—ญ ํŒŒ์ผ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์ž๋™์œผ๋กœ ํƒ€์ž…์„ ์ƒ์„ฑํ•ด์ค˜. ์˜คํƒ€๋‚˜ ๋ˆ„๋ฝ๋œ ๋ฒˆ์—ญ์„ ์ปดํŒŒ์ผ ํƒ€์ž„์— 100% ์žก์•„๋‚ผ ์ˆ˜ ์žˆ์–ด!
// ์ž๋™ ์ƒ์„ฑ๋œ ํƒ€์ž…
type Translation = {
  'welcome': string
  'user.greeting': (name: string) => string
  'items.count': (count: number) => string
}

// ์‚ฌ์šฉํ•  ๋•Œ
LL.welcome() // โœ… OK
LL['user.greeting']('์ฒ ์ˆ˜') // โœ… OK
LL.welcom() // โŒ ์ปดํŒŒ์ผ ์—๋Ÿฌ!
LL['user.greeting']() // โŒ ์ธ์ž ๋ˆ„๋ฝ ์—๋Ÿฌ!

๐Ÿ”ง ํƒ€์ž… ์‹œ์Šคํ…œ ๊ตฌ์ถ•ํ•˜๊ธฐ

์ž, ์ด์ œ ๋ณธ๊ฒฉ์ ์œผ๋กœ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์˜ ํƒ€์ž… ์‹œ์Šคํ…œ์„ ํ™œ์šฉํ•ด์„œ ์•ˆ์ „ํ•œ i18n์„ ๊ตฌ์ถ•ํ•ด๋ณด์ž! ๐ŸŽจ

๊ธฐ๋ณธ ํƒ€์ž… ์ •์˜

๋จผ์ € ๋ฒˆ์—ญ ๊ฐ์ฒด์˜ ๊ตฌ์กฐ๋ฅผ ํƒ€์ž…์œผ๋กœ ์ •์˜ํ•ด์•ผ ํ•ด:

// types/i18n.ts
export interface Translations {
  common: {
    welcome: string;
    goodbye: string;
    loading: string;
  };
  auth: {
    login: string;
    logout: string;
    signup: string;
    forgotPassword: string;
  };
  errors: {
    notFound: string;
    serverError: string;
    unauthorized: string;
  };
}

// ์ง€์›ํ•˜๋Š” ์–ธ์–ด ํƒ€์ž…
export type Locale = 'ko' | 'en' | 'ja';

// ๋ฒˆ์—ญ ํ‚ค ํƒ€์ž… (์ค‘์ฒฉ๋œ ๊ฐ์ฒด์˜ ๋ชจ๋“  ๊ฒฝ๋กœ)
export type TranslationKey = 
  | 'common.welcome'
  | 'common.goodbye'
  | 'common.loading'
  | 'auth.login'
  | 'auth.logout'
  | 'auth.signup'
  | 'auth.forgotPassword'
  | 'errors.notFound'
  | 'errors.serverError'
  | 'errors.unauthorized';

๊ทผ๋ฐ ์ด๋ ‡๊ฒŒ ํ•˜๋‚˜ํ•˜๋‚˜ ํƒ€์ดํ•‘ํ•˜๋Š” ๊ฑด ๋„ˆ๋ฌด ๊ท€์ฐฎ์ž–์•„? ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์˜ ๊ณ ๊ธ‰ ๊ธฐ๋Šฅ์„ ํ™œ์šฉํ•˜๋ฉด ์ž๋™์œผ๋กœ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด!

์ž๋™ ํƒ€์ž… ์ƒ์„ฑ ์œ ํ‹ธ๋ฆฌํ‹ฐ

// ์ค‘์ฒฉ๋œ ๊ฐ์ฒด์˜ ๋ชจ๋“  ๊ฒฝ๋กœ๋ฅผ ํƒ€์ž…์œผ๋กœ ์ถ”์ถœ
type PathsToStringProps<T> = T extends string
  ? []
  : {
      [K in Extract<keyof T, string>]: [K, ...PathsToStringProps<T[K]>];
    }[Extract<keyof T, string>];

type Join<T extends string[], D extends string> = T extends []
  ? never
  : T extends [infer F]
  ? F
  : T extends [infer F, ...infer R]
  ? F extends string
    ? `${F}${D}${Join<Extract<R, string[]>, D>}`
    : never
  : string;

// ์ตœ์ข… ํƒ€์ž… ์ƒ์„ฑ
export type TranslationKey = Join<PathsToStringProps<Translations>, '.'>;

// ์ด์ œ ์ž๋™์œผ๋กœ ๋ชจ๋“  ๊ฒฝ๋กœ๊ฐ€ ํƒ€์ž…์œผ๋กœ ์ƒ์„ฑ๋ผ!
const key: TranslationKey = 'common.welcome'; // โœ…
const invalid: TranslationKey = 'common.invalid'; // โŒ ์—๋Ÿฌ!
โš ๏ธ ์ฃผ์˜์‚ฌํ•ญ ์ด๋Ÿฐ ๊ณ ๊ธ‰ ํƒ€์ž… ๊ธฐ๋Šฅ์€ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ 4.1 ์ด์ƒ์—์„œ๋งŒ ์ œ๋Œ€๋กœ ์ž‘๋™ํ•ด. ํ”„๋กœ์ ํŠธ์˜ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ๋ฒ„์ „์„ ํ™•์ธํ•ด๋ด!

๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์žˆ๋Š” ๋ฒˆ์—ญ ์ฒ˜๋ฆฌ

์‹ค์ œ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ๋™์ ์ธ ๊ฐ’์„ ๋„ฃ์–ด์•ผ ํ•  ๋•Œ๊ฐ€ ๋งŽ์•„. ์˜ˆ๋ฅผ ๋“ค์–ด "์•ˆ๋…•ํ•˜์„ธ์š”, {{name}}๋‹˜!" ๊ฐ™์€ ๊ฑฐ ๋ง์ด์•ผ.

// ๋งค๊ฐœ๋ณ€์ˆ˜ ํƒ€์ž… ์ •์˜
export interface TranslationParams {
  'user.greeting': { name: string };
  'items.count': { count: number };
  'order.total': { amount: number; currency: string };
}

// ๋ฒˆ์—ญ ํ•จ์ˆ˜ ํƒ€์ž…
type TranslateFn = <K extends TranslationKey>(
  key: K,
  ...params: K extends keyof TranslationParams 
    ? [TranslationParams[K]] 
    : []
) => string;

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const t: TranslateFn = (key, params) => {
  // ์‹ค์ œ ๋ฒˆ์—ญ ๋กœ์ง
  return '๋ฒˆ์—ญ๋œ ๋ฌธ์ž์—ด';
};

// ํƒ€์ž… ์•ˆ์ „ํ•˜๊ฒŒ ์‚ฌ์šฉ
t('user.greeting', { name: '์ฒ ์ˆ˜' }); // โœ…
t('user.greeting'); // โŒ ๋งค๊ฐœ๋ณ€์ˆ˜ ํ•„์š”!
t('user.greeting', { age: 20 }); // โŒ ์ž˜๋ชป๋œ ๋งค๊ฐœ๋ณ€์ˆ˜!
t('common.welcome'); // โœ… ๋งค๊ฐœ๋ณ€์ˆ˜ ๋ถˆํ•„์š”
ํƒ€์ž… ์•ˆ์ „ํ•œ ๋ฒˆ์—ญ ์‹œ์Šคํ…œ ๋ฒˆ์—ญ ํŒŒ์ผ ko.json en.json ja.json ๐Ÿ“„ ํƒ€์ž… ์ถ”์ถœ ํƒ€์ž… ์ •์˜ TranslationKey TranslationParams TranslateFn ๐Ÿ”ง ํƒ€์ž… ์•ˆ์ „ํ•œ ๋ฒˆ์—ญ ํ•จ์ˆ˜ ์ž๋™์™„์„ฑ โœ“ ์˜คํƒ€ ๊ฐ์ง€ โœ“ ๋งค๊ฐœ๋ณ€์ˆ˜ ๊ฒ€์ฆ โœ“

๋„ค์ž„์ŠคํŽ˜์ด์Šค ๊ธฐ๋ฐ˜ ํƒ€์ž… ์‹œ์Šคํ…œ

ํ”„๋กœ์ ํŠธ๊ฐ€ ์ปค์ง€๋ฉด ๋ฒˆ์—ญ์„ ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋ณ„๋กœ ๋‚˜๋ˆ„๋Š” ๊ฒŒ ์ข‹์•„. ์˜ˆ๋ฅผ ๋“ค์–ด common, auth, dashboard ์ด๋Ÿฐ ์‹์œผ๋กœ ๋ง์ด์•ผ.

// ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋ณ„ ํƒ€์ž… ์ •์˜
interface CommonTranslations {
  welcome: string;
  goodbye: string;
  loading: string;
}

interface AuthTranslations {
  login: string;
  logout: string;
  signup: string;
}

interface DashboardTranslations {
  overview: string;
  statistics: string;
  settings: string;
}

// ์ „์ฒด ๋ฒˆ์—ญ ํƒ€์ž…
interface AllTranslations {
  common: CommonTranslations;
  auth: AuthTranslations;
  dashboard: DashboardTranslations;
}

// ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋ฅผ ํฌํ•จํ•œ ๋ฒˆ์—ญ ํ•จ์ˆ˜
function createTypedTranslation<T extends AllTranslations>() {
  return function t<
    NS extends keyof T,
    K extends keyof T[NS]
  >(namespace: NS, key: K): string {
    // ์‹ค์ œ ๋ฒˆ์—ญ ๋กœ์ง
    return '';
  };
}

const t = createTypedTranslation<AllTranslations>();

// ์‚ฌ์šฉ
t('common', 'welcome'); // โœ…
t('auth', 'login'); // โœ…
t('common', 'login'); // โŒ common์—๋Š” login์ด ์—†์Œ!
t('dashboard', 'invalid'); // โŒ ์กด์žฌํ•˜์ง€ ์•Š๋Š” ํ‚ค!

๐ŸŽจ ์‹ค์ „ ๊ตฌํ˜„ ํŒจํ„ด

์ด๋ก ์€ ์ถฉ๋ถ„ํžˆ ๋ดค์œผ๋‹ˆ, ์ด์ œ ์‹ค์ œ๋กœ ์–ด๋–ป๊ฒŒ ๊ตฌํ˜„ํ•˜๋Š”์ง€ ํŒจํ„ด๋ณ„๋กœ ์•Œ์•„๋ณด์ž!

ํŒจํ„ด 1: ์ปจํ…์ŠคํŠธ ๊ธฐ๋ฐ˜ ์ ‘๊ทผ

React์—์„œ ๊ฐ€์žฅ ๋งŽ์ด ์“ฐ๋Š” ํŒจํ„ด์ด์•ผ. Context API๋ฅผ ํ™œ์šฉํ•ด์„œ ์ „์—ญ์ ์œผ๋กœ ๋ฒˆ์—ญ ํ•จ์ˆ˜๋ฅผ ์ œ๊ณตํ•˜๋Š” ๊ฑฐ์ง€.

// I18nContext.tsx
import React, { createContext, useContext, useState } from 'react';

interface I18nContextType {
  locale: Locale;
  setLocale: (locale: Locale) => void;
  t: TranslateFn;
}

const I18nContext = createContext<I18nContextType | undefined>(undefined);

export function I18nProvider({ children }: { children: React.ReactNode }) {
  const [locale, setLocale] = useState<Locale>('ko');
  
  const t: TranslateFn = (key, params) => {
    // ๋ฒˆ์—ญ ๋กœ์ง
    const translation = translations[locale][key];
    
    if (params) {
      return Object.entries(params).reduce(
        (str, [key, value]) => str.replace(`{{${key}}}`, String(value)),
        translation
      );
    }
    
    return translation;
  };
  
  return (
    <I18nContext.Provider value={{ locale, setLocale, t }}>
      {children}
    </I18nContext.Provider>
  );
}

export function useI18n() {
  const context = useContext(I18nContext);
  if (!context) {
    throw new Error('useI18n must be used within I18nProvider');
  }
  return context;
}

// ์‚ฌ์šฉ
function MyComponent() {
  const { t, locale, setLocale } = useI18n();
  
  return (
    <div>
      <h1>{t('common.welcome')}</h1>
      <p>{t('user.greeting', { name: '์ฒ ์ˆ˜' })}</p>
      <button onClick={() => setLocale('en')}>English</button>
    </div>
  );
}

ํŒจํ„ด 2: ํ›… ๊ธฐ๋ฐ˜ ์ ‘๊ทผ

๋” ๊ฐ„๋‹จํ•˜๊ฒŒ ์ปค์Šคํ…€ ํ›…๋งŒ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ์–ด:

// useTranslation.ts
import { useState, useCallback } from 'react';

export function useTranslation() {
  const [locale, setLocale] = useState<Locale>('ko');
  
  const t = useCallback<TranslateFn>(
    (key, params) => {
      const translation = getTranslation(locale, key);
      return interpolate(translation, params);
    },
    [locale]
  );
  
  const changeLanguage = useCallback((newLocale: Locale) => {
    setLocale(newLocale);
    localStorage.setItem('locale', newLocale);
  }, []);
  
  return { t, locale, changeLanguage };
}

// ๋ฒˆ์—ญ ๊ฐ€์ ธ์˜ค๊ธฐ
function getTranslation(locale: Locale, key: TranslationKey): string {
  const keys = key.split('.');
  let value: any = translations[locale];
  
  for (const k of keys) {
    value = value[k];
    if (value === undefined) {
      console.warn(`Translation missing: ${key} for locale ${locale}`);
      return key;
    }
  }
  
  return value;
}

// ๋ณ€์ˆ˜ ์น˜ํ™˜
function interpolate(template: string, params?: Record<string, any>): string {
  if (!params) return template;
  
  return template.replace(/\{\{(\w+)\}\}/g, (match, key) => {
    return params[key] !== undefined ? String(params[key]) : match;
  });
}

ํŒจํ„ด 3: ๊ณ ์ฐจ ์ปดํฌ๋„ŒํŠธ(HOC) ํŒจํ„ด

ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ๋ฅผ ์“ฐ๊ฑฐ๋‚˜ ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ๋ฅผ ๋‹ค๋ฃฐ ๋•Œ ์œ ์šฉํ•ด:

// withTranslation.tsx
import React from 'react';

interface WithTranslationProps {
  t: TranslateFn;
  locale: Locale;
  changeLanguage: (locale: Locale) => void;
}

export function withTranslation<P extends WithTranslationProps>(
  Component: React.ComponentType<P>
) {
  return function TranslatedComponent(
    props: Omit<P, keyof WithTranslationProps>
  ) {
    const { t, locale, changeLanguage } = useTranslation();
    
    return (
      <Component
        {...(props as P)}
        t={t}
        locale={locale}
        changeLanguage={changeLanguage}
      />
    );
  };
}

// ์‚ฌ์šฉ
interface MyComponentProps extends WithTranslationProps {
  title: string;
}

class MyComponent extends React.Component<MyComponentProps> {
  render() {
    const { t, title } = this.props;
    return <h1>{t('common.welcome')} - {title}</h1>;
  }
}

export default withTranslation(MyComponent);
๐Ÿ’ก ํŒจํ„ด ์„ ํƒ ๊ฐ€์ด๋“œ ์ปจํ…์ŠคํŠธ ํŒจํ„ด: ์ค‘๋Œ€ํ˜• ํ”„๋กœ์ ํŠธ, ์ „์—ญ ์ƒํƒœ ๊ด€๋ฆฌ ํ•„์š”
ํ›… ํŒจํ„ด: ์†Œํ˜• ํ”„๋กœ์ ํŠธ, ๊ฐ„๋‹จํ•œ ๊ตฌ์กฐ
HOC ํŒจํ„ด: ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ, ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ ์‚ฌ์šฉ

๐Ÿš€ ๊ณ ๊ธ‰ ๊ธฐ๋Šฅ ๊ตฌํ˜„ํ•˜๊ธฐ

1. ๋ณต์ˆ˜ํ˜• ์ฒ˜๋ฆฌ (Pluralization)

์–ธ์–ด๋งˆ๋‹ค ๋ณต์ˆ˜ํ˜• ๊ทœ์น™์ด ๋‹ฌ๋ผ. ์˜์–ด๋Š” 1๊ฐœ์ผ ๋•Œ์™€ 2๊ฐœ ์ด์ƒ์ผ ๋•Œ๋งŒ ๊ตฌ๋ถ„ํ•˜์ง€๋งŒ, ๋Ÿฌ์‹œ์•„์–ด๋Š” ํ›จ์”ฌ ๋ณต์žกํ•ด!

// ๋ณต์ˆ˜ํ˜• ๊ทœ์น™ ์ •์˜
type PluralRule = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';

interface PluralTranslation {
  zero?: string;
  one?: string;
  two?: string;
  few?: string;
  many?: string;
  other: string;
}

// ์–ธ์–ด๋ณ„ ๋ณต์ˆ˜ํ˜• ๊ทœ์น™
function getPluralRule(locale: Locale, count: number): PluralRule {
  const pluralRules = new Intl.PluralRules(locale);
  return pluralRules.select(count) as PluralRule;
}

// ๋ณต์ˆ˜ํ˜• ๋ฒˆ์—ญ ํ•จ์ˆ˜
function translatePlural(
  locale: Locale,
  translation: PluralTranslation,
  count: number
): string {
  const rule = getPluralRule(locale, count);
  const text = translation[rule] || translation.other;
  return text.replace('{{count}}', String(count));
}

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const itemTranslations = {
  ko: {
    other: '{{count}}๊ฐœ์˜ ์•„์ดํ…œ'
  },
  en: {
    one: '{{count}} item',
    other: '{{count}} items'
  }
};

console.log(translatePlural('en', itemTranslations.en, 1)); // "1 item"
console.log(translatePlural('en', itemTranslations.en, 5)); // "5 items"
console.log(translatePlural('ko', itemTranslations.ko, 5)); // "5๊ฐœ์˜ ์•„์ดํ…œ"

2. ๋‚ ์งœ์™€ ์ˆซ์ž ํฌ๋งทํŒ…

๋ฒˆ์—ญ๋งŒํผ์ด๋‚˜ ์ค‘์š”ํ•œ ๊ฒŒ ๋‚ ์งœ์™€ ์ˆซ์ž ํ˜•์‹์ด์•ผ. ํ•œ๊ตญ์€ "2024๋…„ 1์›” 15์ผ"์ด์ง€๋งŒ ๋ฏธ๊ตญ์€ "January 15, 2024"์ž–์•„?

// ๋‚ ์งœ ํฌ๋งทํŒ…
function formatDate(locale: Locale, date: Date, options?: Intl.DateTimeFormatOptions): string {
  return new Intl.DateTimeFormat(locale, options).format(date);
}

// ์ˆซ์ž ํฌ๋งทํŒ…
function formatNumber(locale: Locale, number: number, options?: Intl.NumberFormatOptions): string {
  return new Intl.NumberFormat(locale, options).format(number);
}

// ํ†ตํ™” ํฌ๋งทํŒ…
function formatCurrency(locale: Locale, amount: number, currency: string): string {
  return new Intl.NumberFormat(locale, {
    style: 'currency',
    currency: currency
  }).format(amount);
}

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const date = new Date('2024-01-15');

console.log(formatDate('ko', date)); // "2024. 1. 15."
console.log(formatDate('en', date)); // "1/15/2024"
console.log(formatDate('ja', date)); // "2024/1/15"

console.log(formatNumber('ko', 1234567.89)); // "1,234,567.89"
console.log(formatNumber('de', 1234567.89)); // "1.234.567,89"

console.log(formatCurrency('ko', 10000, 'KRW')); // "โ‚ฉ10,000"
console.log(formatCurrency('en', 10000, 'USD')); // "$10,000.00"

3. ์ง€์—ฐ ๋กœ๋”ฉ (Lazy Loading)

๋ชจ๋“  ์–ธ์–ด์˜ ๋ฒˆ์—ญ ํŒŒ์ผ์„ ํ•œ ๋ฒˆ์— ๋กœ๋“œํ•˜๋ฉด ์ดˆ๊ธฐ ๋กœ๋”ฉ์ด ๋А๋ ค์ ธ. ํ•„์š”ํ•  ๋•Œ๋งŒ ๋กœ๋“œํ•˜๋Š” ๊ฒŒ ์ข‹์•„!

// ๋ฒˆ์—ญ ํŒŒ์ผ ๋™์  ๋กœ๋”ฉ
const translationCache = new Map<Locale, AllTranslations>();

async function loadTranslations(locale: Locale): Promise<AllTranslations> {
  // ์บ์‹œ ํ™•์ธ
  if (translationCache.has(locale)) {
    return translationCache.get(locale)!;
  }
  
  // ๋™์  import
  const translations = await import(`./locales/${locale}.json`);
  
  // ์บ์‹œ ์ €์žฅ
  translationCache.set(locale, translations.default);
  
  return translations.default;
}

// React์—์„œ ์‚ฌ์šฉ
function I18nProvider({ children }: { children: React.ReactNode }) {
  const [locale, setLocale] = useState<Locale>('ko');
  const [translations, setTranslations] = useState<AllTranslations | null>(null);
  const [loading, setLoading] = useState(true);
  
  useEffect(() => {
    setLoading(true);
    loadTranslations(locale)
      .then(setTranslations)
      .finally(() => setLoading(false));
  }, [locale]);
  
  if (loading || !translations) {
    return <div>Loading...</div>;
  }
  
  // ... ๋‚˜๋จธ์ง€ ๋กœ์ง
}

4. ๋ฒˆ์—ญ ๋ˆ„๋ฝ ๊ฐ์ง€

๊ฐœ๋ฐœํ•˜๋‹ค ๋ณด๋ฉด ๋ฒˆ์—ญ์„ ๊นœ๋นกํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์–ด. ์ด๊ฑธ ์ž๋™์œผ๋กœ ๊ฐ์ง€ํ•˜๋ฉด ์ข‹๊ฒ ์ง€?

// ๋ฒˆ์—ญ ๋ˆ„๋ฝ ์ฒดํฌ ์œ ํ‹ธ๋ฆฌํ‹ฐ
interface MissingTranslation {
  key: TranslationKey;
  locale: Locale;
}

class TranslationValidator {
  private missingTranslations: MissingTranslation[] = [];
  
  validate(locales: Locale[], baseLocale: Locale = 'ko'): MissingTranslation[] {
    this.missingTranslations = [];
    
    const baseKeys = this.getAllKeys(translations[baseLocale]);
    
    for (const locale of locales) {
      if (locale === baseLocale) continue;
      
      const localeKeys = this.getAllKeys(translations[locale]);
      
      for (const key of baseKeys) {
        if (!localeKeys.includes(key)) {
          this.missingTranslations.push({ key: key as TranslationKey, locale });
        }
      }
    }
    
    return this.missingTranslations;
  }
  
  private getAllKeys(obj: any, prefix = ''): string[] {
    let keys: string[] = [];
    
    for (const [key, value] of Object.entries(obj)) {
      const fullKey = prefix ? `${prefix}.${key}` : key;
      
      if (typeof value === 'object' && value !== null) {
        keys = keys.concat(this.getAllKeys(value, fullKey));
      } else {
        keys.push(fullKey);
      }
    }
    
    return keys;
  }
  
  report(): void {
    if (this.missingTranslations.length === 0) {
      console.log('โœ… All translations are complete!');
      return;
    }
    
    console.warn('โš ๏ธ Missing translations:');
    for (const { key, locale } of this.missingTranslations) {
      console.warn(`  - ${locale}: ${key}`);
    }
  }
}

// ์‚ฌ์šฉ
const validator = new TranslationValidator();
const missing = validator.validate(['ko', 'en', 'ja']);
validator.report();

๐ŸŽฏ ์‹ค์ „ ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ

์ด์ œ ์‹ค์ œ ํ”„๋กœ์ ํŠธ์—์„œ ์–ด๋–ป๊ฒŒ ๊ตฌ์กฐ๋ฅผ ์žก๋Š”์ง€ ์•Œ์•„๋ณด์ž. ์ด๊ฑด ๋‚ด๊ฐ€ ์‹ค๋ฌด์—์„œ ์จ๋ณธ ๊ตฌ์กฐ์•ผ!

src/
โ”œโ”€โ”€ i18n/
โ”‚   โ”œโ”€โ”€ locales/
โ”‚   โ”‚   โ”œโ”€โ”€ ko/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ common.json
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ auth.json
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ dashboard.json
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ errors.json
โ”‚   โ”‚   โ”œโ”€โ”€ en/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ common.json
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ auth.json
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ dashboard.json
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ errors.json
โ”‚   โ”‚   โ””โ”€โ”€ ja/
โ”‚   โ”‚       โ”œโ”€โ”€ common.json
โ”‚   โ”‚       โ”œโ”€โ”€ auth.json
โ”‚   โ”‚       โ”œโ”€โ”€ dashboard.json
โ”‚   โ”‚       โ””โ”€โ”€ errors.json
โ”‚   โ”œโ”€โ”€ types/
โ”‚   โ”‚   โ”œโ”€โ”€ translations.ts
โ”‚   โ”‚   โ”œโ”€โ”€ locale.ts
โ”‚   โ”‚   โ””โ”€โ”€ params.ts
โ”‚   โ”œโ”€โ”€ utils/
โ”‚   โ”‚   โ”œโ”€โ”€ interpolate.ts
โ”‚   โ”‚   โ”œโ”€โ”€ pluralize.ts
โ”‚   โ”‚   โ””โ”€โ”€ format.ts
โ”‚   โ”œโ”€โ”€ hooks/
โ”‚   โ”‚   โ”œโ”€โ”€ useTranslation.ts
โ”‚   โ”‚   โ””โ”€โ”€ useLocale.ts
โ”‚   โ”œโ”€โ”€ context/
โ”‚   โ”‚   โ””โ”€โ”€ I18nContext.tsx
โ”‚   โ”œโ”€โ”€ config.ts
โ”‚   โ””โ”€โ”€ index.ts
โ””โ”€โ”€ ...

config.ts - ์„ค์ • ํŒŒ์ผ

// i18n/config.ts
export const i18nConfig = {
  // ์ง€์›ํ•˜๋Š” ์–ธ์–ด
  locales: ['ko', 'en', 'ja'] as const,
  
  // ๊ธฐ๋ณธ ์–ธ์–ด
  defaultLocale: 'ko' as const,
  
  // ํด๋ฐฑ ์–ธ์–ด
  fallbackLocale: 'en' as const,
  
  // ๋„ค์ž„์ŠคํŽ˜์ด์Šค
  namespaces: ['common', 'auth', 'dashboard', 'errors'] as const,
  
  // ๋กœ์ปฌ ์Šคํ† ๋ฆฌ์ง€ ํ‚ค
  storageKey: 'app_locale',
  
  // ๋””๋ฒ„๊ทธ ๋ชจ๋“œ
  debug: process.env.NODE_ENV === 'development',
  
  // ๋ˆ„๋ฝ๋œ ๋ฒˆ์—ญ ์ฒ˜๋ฆฌ
  missingKeyHandler: (locale: string, key: string) => {
    if (i18nConfig.debug) {
      console.warn(`Missing translation: ${key} for locale ${locale}`);
    }
    return key;
  }
} as const;

export type I18nConfig = typeof i18nConfig;
export type SupportedLocale = typeof i18nConfig.locales[number];
export type Namespace = typeof i18nConfig.namespaces[number];

index.ts - ์ง„์ž…์ 

// i18n/index.ts
export { I18nProvider, useI18n } from './context/I18nContext';
export { useTranslation } from './hooks/useTranslation';
export { useLocale } from './hooks/useLocale';
export { i18nConfig } from './config';
export type { 
  SupportedLocale, 
  Namespace, 
  TranslationKey,
  TranslationParams 
} from './types';

// ํŽธ์˜ ํ•จ์ˆ˜๋“ค
export { formatDate, formatNumber, formatCurrency } from './utils/format';
export { pluralize } from './utils/pluralize';

๐Ÿ” ํ…Œ์ŠคํŒ… ์ „๋žต

i18n ์‹œ์Šคํ…œ๋„ ๋‹น์—ฐํžˆ ํ…Œ์ŠคํŠธํ•ด์•ผ ํ•ด! ํŠนํžˆ ํƒ€์ž… ์•ˆ์ •์„ฑ์„ ๊ฒ€์ฆํ•˜๋Š” ๊ฒŒ ์ค‘์š”ํ•˜์ง€.

๋‹จ์œ„ ํ…Œ์ŠคํŠธ

// __tests__/i18n.test.ts
import { describe, it, expect } from 'vitest';
import { useTranslation } from '../i18n';

describe('Translation System', () => {
  it('should translate simple keys', () => {
    const { t } = useTranslation();
    expect(t('common.welcome')).toBe('ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค!');
  });
  
  it('should interpolate parameters', () => {
    const { t } = useTranslation();
    expect(t('user.greeting', { name: '์ฒ ์ˆ˜' })).toBe('์•ˆ๋…•ํ•˜์„ธ์š”, ์ฒ ์ˆ˜๋‹˜!');
  });
  
  it('should handle missing translations', () => {
    const { t } = useTranslation();
    expect(t('nonexistent.key' as any)).toBe('nonexistent.key');
  });
  
  it('should change locale', () => {
    const { t, changeLanguage } = useTranslation();
    
    expect(t('common.welcome')).toBe('ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค!');
    
    changeLanguage('en');
    expect(t('common.welcome')).toBe('Welcome!');
  });
});

ํƒ€์ž… ํ…Œ์ŠคํŠธ

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์˜ ํƒ€์ž… ์‹œ์Šคํ…œ ์ž์ฒด๋ฅผ ํ…Œ์ŠคํŠธํ•  ์ˆ˜๋„ ์žˆ์–ด!

// __tests__/types.test.ts
import { expectType, expectError } from 'tsd';
import type { TranslationKey, TranslateFn } from '../i18n/types';

// ์˜ฌ๋ฐ”๋ฅธ ํ‚ค๋Š” ํ—ˆ์šฉ
expectType<TranslationKey>('common.welcome');
expectType<TranslationKey>('auth.login');

// ์ž˜๋ชป๋œ ํ‚ค๋Š” ์—๋Ÿฌ
expectError<TranslationKey>('invalid.key');

// ๋ฒˆ์—ญ ํ•จ์ˆ˜ ํƒ€์ž… ๊ฒ€์ฆ
declare const t: TranslateFn;

// ๋งค๊ฐœ๋ณ€์ˆ˜ ์—†๋Š” ๋ฒˆ์—ญ
expectType<string>(t('common.welcome'));

// ๋งค๊ฐœ๋ณ€์ˆ˜ ์žˆ๋Š” ๋ฒˆ์—ญ
expectType<string>(t('user.greeting', { name: 'test' }));

// ์ž˜๋ชป๋œ ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ์—๋Ÿฌ
expectError(t('user.greeting', { age: 20 }));
expectError(t('user.greeting')); // ๋งค๊ฐœ๋ณ€์ˆ˜ ๋ˆ„๋ฝ

ํ†ตํ•ฉ ํ…Œ์ŠคํŠธ

// __tests__/integration.test.tsx
import { render, screen, fireEvent } from '@testing-library/react';
import { I18nProvider } from '../i18n';
import MyComponent from '../components/MyComponent';

describe('I18n Integration', () => {
  it('should render translated content', () => {
    render(
      <I18nProvider>
        <MyComponent />
      </I18nProvider>
    );
    
    expect(screen.getByText('ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค!')).toBeInTheDocument();
  });
  
  it('should change language on button click', () => {
    render(
      <I18nProvider>
        <MyComponent />
      </I18nProvider>
    );
    
    const button = screen.getByText('English');
    fireEvent.click(button);
    
    expect(screen.getByText('Welcome!')).toBeInTheDocument();
  });
});

โšก ์„ฑ๋Šฅ ์ตœ์ ํ™”

i18n ์‹œ์Šคํ…œ์ด ๋А๋ฆฌ๋ฉด ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์ด ๋‚˜๋น ์ ธ. ๋ช‡ ๊ฐ€์ง€ ์ตœ์ ํ™” ๊ธฐ๋ฒ•์„ ์•Œ์•„๋ณด์ž!

1. ๋ฉ”๋ชจ์ด์ œ์ด์…˜

import { useMemo } from 'react';

function useTranslation() {
  const [locale] = useLocale();
  
  // ๋ฒˆ์—ญ ํ•จ์ˆ˜ ๋ฉ”๋ชจ์ด์ œ์ด์…˜
  const t = useMemo<TranslateFn>(() => {
    return (key, params) => {
      const translation = getTranslation(locale, key);
      return params ? interpolate(translation, params) : translation;
    };
  }, [locale]);
  
  return { t, locale };
}

// ๋ฒˆ์—ญ ๊ฒฐ๊ณผ ์บ์‹ฑ
const translationCache = new Map<string, string>();

function getTranslation(locale: Locale, key: TranslationKey): string {
  const cacheKey = `${locale}:${key}`;
  
  if (translationCache.has(cacheKey)) {
    return translationCache.get(cacheKey)!;
  }
  
  const translation = fetchTranslation(locale, key);
  translationCache.set(cacheKey, translation);
  
  return translation;
}

2. ์ฝ”๋“œ ์Šคํ”Œ๋ฆฌํŒ…

// ๋ผ์šฐํŠธ๋ณ„๋กœ ๋ฒˆ์—ญ ํŒŒ์ผ ๋ถ„๋ฆฌ
const DashboardPage = lazy(() => 
  Promise.all([
    import('./pages/Dashboard'),
    import('./i18n/locales/ko/dashboard.json')
  ]).then(([module]) => module)
);

// ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋ณ„ ์ง€์—ฐ ๋กœ๋”ฉ
async function loadNamespace(locale: Locale, namespace: Namespace) {
  const translations = await import(
    `./i18n/locales/${locale}/${namespace}.json`
  );
  
  return translations.default;
}

3. ๋ฒˆ๋“ค ํฌ๊ธฐ ์ตœ์ ํ™”

// webpack.config.js
module.exports = {
  optimization: {
    splitChunks: {
      cacheGroups: {
        i18n: {
          test: /[\\/]i18n[\\/]locales[\\/]/,
          name: 'i18n',
          chunks: 'all',
          priority: 10
        }
      }
    }
  }
};

// ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๋ฒˆ์—ญ ์ œ๊ฑฐ
// tree-shaking์„ ์œ„ํ•ด named export ์‚ฌ์šฉ
export const translations = {
  common: {
    welcome: 'ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค!'
  }
} as const;
์„ฑ๋Šฅ ์ตœ์ ํ™” ์ „๋žต ๋ฉ”๋ชจ์ด์ œ์ด์…˜ โ€ข ๋ฒˆ์—ญ ํ•จ์ˆ˜ ์บ์‹ฑ โ€ข ๊ฒฐ๊ณผ๊ฐ’ ์ €์žฅ โ€ข ๋ถˆํ•„์š”ํ•œ ์žฌ๊ณ„์‚ฐ ๋ฐฉ์ง€ ๐Ÿ’พ ~40% ๋น ๋ฆ„ ์ฝ”๋“œ ์Šคํ”Œ๋ฆฌํŒ… โ€ข ์ง€์—ฐ ๋กœ๋”ฉ โ€ข ๋ผ์šฐํŠธ๋ณ„ ๋ถ„๋ฆฌ โ€ข ํ•„์š”ํ•  ๋•Œ๋งŒ ๋กœ๋“œ ๐Ÿ“ฆ ~60% ์ž‘์Œ ๋ฒˆ๋“ค ์ตœ์ ํ™” โ€ข Tree shaking โ€ข ์••์ถ• โ€ข ๋ฏธ์‚ฌ์šฉ ์ฝ”๋“œ ์ œ๊ฑฐ ๐Ÿ—œ๏ธ ~50% ์ž‘์Œ

๐Ÿ› ๏ธ ์‹ค๋ฌด ํŒ๊ณผ ๋ฒ ์ŠคํŠธ ํ”„๋ž™ํ‹ฐ์Šค

์ด์ œ ์‹ค๋ฌด์—์„œ ๋ฐ”๋กœ ์“ธ ์ˆ˜ ์žˆ๋Š” ํŒ๋“ค์„ ๊ณต์œ ํ• ๊ฒŒ! ์ด๊ฑด ์ง„์งœ ๊ฒฝํ—˜์—์„œ ๋‚˜์˜จ ๊ฑฐ์•ผ. ๐Ÿ˜Š

โœ… DO - ์ด๋ ‡๊ฒŒ ํ•˜์„ธ์š”

1. ๋ฒˆ์—ญ ํ‚ค๋Š” ์˜๋ฏธ ์žˆ๊ฒŒ ์ž‘์„ฑํ•˜๊ธฐ

// โœ… Good
'auth.login.button.submit'
'dashboard.user.profile.edit'
'errors.validation.email.invalid'

// โŒ Bad
'button1'
'text123'
'error_msg'

2. ๋„ค์ž„์ŠคํŽ˜์ด์Šค ํ™œ์šฉํ•˜๊ธฐ

// โœ… Good - ๊ธฐ๋Šฅ๋ณ„๋กœ ๋ถ„๋ฆฌ
{
  common: { ... },
  auth: { ... },
  dashboard: { ... }
}

// โŒ Bad - ๋ชจ๋“  ๋ฒˆ์—ญ์„ ํ•œ ํŒŒ์ผ์—
{
  welcome: '...',
  login: '...',
  dashboard_title: '...'
}

3. ๋ณ€์ˆ˜๋ช…์€ ๋ช…ํ™•ํ•˜๊ฒŒ

// โœ… Good
t('user.greeting', { userName: '์ฒ ์ˆ˜', loginCount: 5 })

// โŒ Bad
t('user.greeting', { x: '์ฒ ์ˆ˜', n: 5 })

โŒ DON'T - ์ด๊ฑด ํ”ผํ•˜์„ธ์š”

1. ๋ฒˆ์—ญ ์•ˆ์— HTML ๋„ฃ์ง€ ์•Š๊ธฐ

// โŒ Bad
{
  "message": "<strong>์•ˆ๋…•ํ•˜์„ธ์š”</strong> {{name}}๋‹˜"
}

// โœ… Good - ์ปดํฌ๋„ŒํŠธ์—์„œ ์ฒ˜๋ฆฌ
{
  "greeting": "์•ˆ๋…•ํ•˜์„ธ์š”",
  "name": "{{name}}๋‹˜"
}

<div>
  <strong>{t('greeting')}</strong> {t('name', { name })}
</div>

2. ๋ฌธ์žฅ์„ ์ชผ๊ฐœ์ง€ ์•Š๊ธฐ

// โŒ Bad - ์–ธ์–ด๋งˆ๋‹ค ์–ด์ˆœ์ด ๋‹ค๋ฆ„
{
  "you_have": "๋‹น์‹ ์€",
  "items": "๊ฐœ์˜ ์•„์ดํ…œ์„",
  "have": "๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค"
}

// โœ… Good - ์™„์ „ํ•œ ๋ฌธ์žฅ์œผ๋กœ
{
  "items_count": "{{count}}๊ฐœ์˜ ์•„์ดํ…œ์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค"
}

3. ํ•˜๋“œ์ฝ”๋”ฉ๋œ ํ…์ŠคํŠธ ๋‚จ๊ธฐ์ง€ ์•Š๊ธฐ

// โŒ Bad
<button>ํ™•์ธ</button>

// โœ… Good
<button>{t('common.confirm')}</button>
๐ŸŽฏ ํ”„๋กœ ํŒ ๋ฒˆ์—ญ ํ‚ค๋ฅผ ์ž‘์„ฑํ•  ๋•Œ๋Š” ํ•ญ์ƒ "์ด ํ‚ค๋ฅผ 6๊ฐœ์›” ํ›„์— ๋ด๋„ ๋ฌด์Šจ ์˜๋ฏธ์ธ์ง€ ์•Œ ์ˆ˜ ์žˆ์„๊นŒ?"๋ฅผ ์ž๋ฌธํ•ด๋ด. ๋ฏธ๋ž˜์˜ ๋‚˜(๋˜๋Š” ๋™๋ฃŒ)๋ฅผ ์œ„ํ•œ ๋ฐฐ๋ ค์•ผ!

๐ŸŒŸ ์‹ค์ „ ์˜ˆ์ œ: ์™„์ „ํ•œ ๋‹ค๊ตญ์–ด ์•ฑ ๋งŒ๋“ค๊ธฐ

์ž, ์ด์ œ ๋ฐฐ์šด ๊ฑธ ๋‹ค ํ•ฉ์ณ์„œ ์‹ค์ œ๋กœ ๋™์ž‘ํ•˜๋Š” ์•ฑ์„ ๋งŒ๋“ค์–ด๋ณด์ž! ๊ฐ„๋‹จํ•œ ํ•  ์ผ ๊ด€๋ฆฌ ์•ฑ์„ ๋งŒ๋“ค ๊ฑฐ์•ผ.

1๋‹จ๊ณ„: ํ”„๋กœ์ ํŠธ ์„ค์ •

// package.json
{
  "dependencies": {
    "react": "^18.2.0",
    "typescript": "^5.0.0",
    "i18next": "^23.0.0",
    "react-i18next": "^13.0.0"
  }
}

// tsconfig.json
{
  "compilerOptions": {
    "strict": true,
    "esModuleInterop": true,
    "resolveJsonModule": true
  }
}

2๋‹จ๊ณ„: ๋ฒˆ์—ญ ํŒŒ์ผ ์ž‘์„ฑ

// locales/ko/translation.json
{
  "app": {
    "title": "ํ•  ์ผ ๊ด€๋ฆฌ",
    "subtitle": "์˜ค๋Š˜ ํ•  ์ผ์„ ๊ด€๋ฆฌํ•˜์„ธ์š”"
  },
  "todo": {
    "add": "ํ•  ์ผ ์ถ”๊ฐ€",
    "placeholder": "๋ฌด์—‡์„ ํ•˜์‹œ๊ฒ ์–ด์š”?",
    "empty": "ํ•  ์ผ์ด ์—†์Šต๋‹ˆ๋‹ค",
    "completed": "์™„๋ฃŒ๋จ",
    "delete": "์‚ญ์ œ",
    "count": "{{count}}๊ฐœ์˜ ํ•  ์ผ"
  },
  "language": {
    "select": "์–ธ์–ด ์„ ํƒ",
    "ko": "ํ•œ๊ตญ์–ด",
    "en": "English",
    "ja": "ๆ—ฅๆœฌ่ชž"
  }
}

// locales/en/translation.json
{
  "app": {
    "title": "Todo Manager",
    "subtitle": "Manage your daily tasks"
  },
  "todo": {
    "add": "Add Todo",
    "placeholder": "What do you want to do?",
    "empty": "No todos yet",
    "completed": "Completed",
    "delete": "Delete",
    "count_one": "{{count}} todo",
    "count_other": "{{count}} todos"
  },
  "language": {
    "select": "Select Language",
    "ko": "ํ•œ๊ตญ์–ด",
    "en": "English",
    "ja": "ๆ—ฅๆœฌ่ชž"
  }
}

3๋‹จ๊ณ„: ํƒ€์ž… ์ •์˜

// types/i18n.ts
import translation from '../locales/ko/translation.json';

export type TranslationResource = typeof translation;

declare module 'i18next' {
  interface CustomTypeOptions {
    defaultNS: 'translation';
    resources: {
      translation: TranslationResource;
    };
  }
}

4๋‹จ๊ณ„: i18n ์„ค์ •

// i18n/config.ts
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import ko from '../locales/ko/translation.json';
import en from '../locales/en/translation.json';
import ja from '../locales/ja/translation.json';

i18n
  .use(initReactI18next)
  .init({
    resources: {
      ko: { translation: ko },
      en: { translation: en },
      ja: { translation: ja }
    },
    lng: localStorage.getItem('locale') || 'ko',
    fallbackLng: 'ko',
    interpolation: {
      escapeValue: false
    }
  });

export default i18n;

5๋‹จ๊ณ„: ์ปดํฌ๋„ŒํŠธ ์ž‘์„ฑ

// App.tsx
import { useState } from 'react';
import { useTranslation } from 'react-i18next';

interface Todo {
  id: number;
  text: string;
  completed: boolean;
}

function App() {
  const { t, i18n } = useTranslation();
  const [todos, setTodos] = useState<Todo[]>([]);
  const [input, setInput] = useState('');

  const addTodo = () => {
    if (!input.trim()) return;
    
    setTodos([
      ...todos,
      { id: Date.now(), text: input, completed: false }
    ]);
    setInput('');
  };

  const toggleTodo = (id: number) => {
    setTodos(todos.map(todo =>
      todo.id === id ? { ...todo, completed: !todo.completed } : todo
    ));
  };

  const deleteTodo = (id: number) => {
    setTodos(todos.filter(todo => todo.id !== id));
  };

  const changeLanguage = (lng: string) => {
    i18n.changeLanguage(lng);
    localStorage.setItem('locale', lng);
  };

  return (
    <div style={{ maxWidth: '600px', margin: '0 auto', padding: '20px' }}>
      <header>
        <h1>{t('app.title')}</h1>
        <p>{t('app.subtitle')}</p>
        
        <select 
          value={i18n.language} 
          onChange={(e) => changeLanguage(e.target.value)}
        >
          <option value="ko">{t('language.ko')}</option>
          <option value="en">{t('language.en')}</option>
          <option value="ja">{t('language.ja')}</option>
        </select>
      </header>

      <div>
        <input
          type="text"
          value={input}
          onChange={(e) => setInput(e.target.value)}
          onKeyPress={(e) => e.key === 'Enter' && addTodo()}
          placeholder={t('todo.placeholder')}
        />
        <button onClick={addTodo}>{t('todo.add')}</button>
      </div>

      <p>{t('todo.count', { count: todos.length })}</p>

      {todos.length === 0 ? (
        <p>{t('todo.empty')}</p>
      ) : (
        <ul>
          {todos.map(todo => (
            <li key={todo.id}>
              <input
                type="checkbox"
                checked={todo.completed}
                onChange={() => toggleTodo(todo.id)}
              />
              <span style={{ 
                textDecoration: todo.completed ? 'line-through' : 'none' 
              }}>
                {todo.text}
              </span>
              {todo.completed && <span> ({t('todo.completed')})</span>}
              <button onClick={() => deleteTodo(todo.id)}>
                {t('todo.delete')}
              </button>
            </li>
          ))}
        </ul>
      )}
    </div>
  );
}

export default App;

์งœ์ž”! ๐ŸŽ‰ ์ด์ œ ์™„์ „ํžˆ ํƒ€์ž… ์•ˆ์ „ํ•œ ๋‹ค๊ตญ์–ด ์•ฑ์ด ์™„์„ฑ๋์–ด. IDE์—์„œ ์ž๋™์™„์„ฑ๋„ ๋˜๊ณ , ์˜คํƒ€๋„ ๋ฐ”๋กœ ์žก์•„์ฃผ์ง€!

๐Ÿšจ ํ”ํ•œ ์‹ค์ˆ˜์™€ ํ•ด๊ฒฐ๋ฒ•

์‹ค๋ฌด์—์„œ ์ž์ฃผ ๋งˆ์ฃผ์น˜๋Š” ๋ฌธ์ œ๋“ค๊ณผ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์„ ์ •๋ฆฌํ•ด๋ดค์–ด.

๋ฌธ์ œ 1: ๋ฒˆ์—ญ์ด ์ฆ‰์‹œ ๋ฐ˜์˜๋˜์ง€ ์•Š์Œ

์›์ธ: ๋ฒˆ์—ญ ํŒŒ์ผ์„ ์ˆ˜์ •ํ–ˆ๋Š”๋ฐ ์บ์‹œ ๋•Œ๋ฌธ์— ๋ฐ˜์˜์ด ์•ˆ ๋จ
ํ•ด๊ฒฐ: ๊ฐœ๋ฐœ ๋ชจ๋“œ์—์„œ๋Š” ์บ์‹œ ๋น„ํ™œ์„ฑํ™”
i18n.init({
  cache: {
    enabled: process.env.NODE_ENV === 'production'
  }
});
๋ฌธ์ œ 2: ํƒ€์ž… ์ถ”๋ก ์ด ์ œ๋Œ€๋กœ ์•ˆ ๋จ

์›์ธ: ํƒ€์ž… ์ •์˜๊ฐ€ ์ œ๋Œ€๋กœ import๋˜์ง€ ์•Š์Œ
ํ•ด๊ฒฐ: tsconfig.json์—์„œ ํƒ€์ž… ๊ฒฝ๋กœ ํ™•์ธ
{
  "compilerOptions": {
    "typeRoots": ["./node_modules/@types", "./src/types"]
  }
}
๋ฌธ์ œ 3: ๋ฒˆ์—ญ ํ‚ค๊ฐ€ ๋„ˆ๋ฌด ๊ธธ์–ด์ง

์›์ธ: ๊นŠ์€ ์ค‘์ฒฉ ๊ตฌ์กฐ
ํ•ด๊ฒฐ: ๋„ค์ž„์ŠคํŽ˜์ด์Šค ํ™œ์šฉ
// โŒ Bad
t('pages.dashboard.user.profile.settings.general.name')

// โœ… Good
const { t } = useTranslation('dashboard');
t('user.profile.name')

๐Ÿ“ˆ ํ”„๋กœ์ ํŠธ ํ™•์žฅํ•˜๊ธฐ

ํ”„๋กœ์ ํŠธ๊ฐ€ ์ปค์ง€๋ฉด์„œ ๊ณ ๋ คํ•ด์•ผ ํ•  ๊ฒƒ๋“ค์„ ์•Œ์•„๋ณด์ž.

1. ๋ฒˆ์—ญ ๊ด€๋ฆฌ ์‹œ์Šคํ…œ ๋„์ž…

๋ฒˆ์—ญ๊ฐ€์™€ ํ˜‘์—…ํ•  ๋•Œ๋Š” ์ „๋ฌธ ๋„๊ตฌ๋ฅผ ์“ฐ๋Š” ๊ฒŒ ์ข‹์•„:

๐Ÿ› ๏ธ ์ถ”์ฒœ ๋„๊ตฌ โ€ข Lokalise: ํ˜‘์—… ๊ธฐ๋Šฅ์ด ๊ฐ•๋ ฅํ•จ
โ€ข Crowdin: ์˜คํ”ˆ์†Œ์Šค ํ”„๋กœ์ ํŠธ์— ์ข‹์Œ
โ€ข Phrase: ๊ฐœ๋ฐœ์ž ์นœํ™”์ 
โ€ข POEditor: ๊ฐ€์„ฑ๋น„ ์ข‹์Œ

2. CI/CD ํ†ตํ•ฉ

// .github/workflows/i18n.yml
name: Check Translations

on: [push, pull_request]

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      
      - name: Install dependencies
        run: npm install
      
      - name: Check missing translations
        run: npm run i18n:validate
      
      - name: Check type safety
        run: npm run type-check

3. ์ž๋™ํ™” ์Šคํฌ๋ฆฝํŠธ

// scripts/extract-translations.ts
import * as fs from 'fs';
import * as path from 'path';

// ์†Œ์Šค ์ฝ”๋“œ์—์„œ ์‚ฌ์šฉ๋œ ๋ฒˆ์—ญ ํ‚ค ์ถ”์ถœ
function extractTranslationKeys(sourceDir: string): Set<string> {
  const keys = new Set<string>();
  const files = getAllFiles(sourceDir);
  
  for (const file of files) {
    const content = fs.readFileSync(file, 'utf-8');
    
    // t('key') ํŒจํ„ด ์ฐพ๊ธฐ
    const matches = content.matchAll(/t\(['"]([^'"]+)['"]\)/g);
    for (const match of matches) {
      keys.add(match[1]);
    }
  }
  
  return keys;
}

// ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ๋ฒˆ์—ญ ํ‚ค ์ฐพ๊ธฐ
function findUnusedKeys(
  usedKeys: Set<string>,
  translationKeys: Set<string>
): string[] {
  return Array.from(translationKeys).filter(key => !usedKeys.has(key));
}

// ์‹คํ–‰
const usedKeys = extractTranslationKeys('./src');
const translationKeys = getAllTranslationKeys('./locales');
const unused = findUnusedKeys(usedKeys, translationKeys);

console.log(`Found ${unused.length} unused translation keys:`);
unused.forEach(key => console.log(`  - ${key}`));

๐ŸŽ“ ํ•™์Šต ๋ฆฌ์†Œ์Šค

๋” ๊นŠ์ด ๊ณต๋ถ€ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์ด๋Ÿฐ ์ž๋ฃŒ๋“ค์„ ์ถ”์ฒœํ•ด:

๐Ÿ“š ๊ณต์‹ ๋ฌธ์„œ

โ€ข i18next ๊ณต์‹ ๋ฌธ์„œ: https://www.i18next.com/
โ€ข react-i18next: https://react.i18next.com/
โ€ข TypeScript ํ•ธ๋“œ๋ถ: https://www.typescriptlang.org/docs/

๐ŸŽฅ ์ถ”์ฒœ ๊ฐ•์˜

โ€ข Udemy: "React Internationalization with i18next"
โ€ข Frontend Masters: "TypeScript Fundamentals"
โ€ข YouTube: "i18n Best Practices" ์‹œ๋ฆฌ์ฆˆ

๐Ÿ’ฌ ์ปค๋ฎค๋‹ˆํ‹ฐ

โ€ข i18next Discord ์„œ๋ฒ„
โ€ข Stack Overflow์˜ i18next ํƒœ๊ทธ
โ€ข Reddit์˜ r/typescript ์ปค๋ฎค๋‹ˆํ‹ฐ

๊ทธ๋ฆฌ๊ณ  ์žฌ๋Šฅ๋„ท์—์„œ๋„ i18n์ด๋‚˜ TypeScript ๊ด€๋ จ ์žฌ๋Šฅ์„ ๊ฐ€์ง„ ์ „๋ฌธ๊ฐ€๋“ค์„ ๋งŒ๋‚  ์ˆ˜ ์žˆ์–ด. ๋ง‰ํžˆ๋Š” ๋ถ€๋ถ„์ด ์žˆ์œผ๋ฉด ๋„์›€์„ ๋ฐ›๋Š” ๊ฒƒ๋„ ์ข‹์€ ๋ฐฉ๋ฒ•์ด์•ผ!

๐ŸŽฏ ๋งˆ๋ฌด๋ฆฌํ•˜๋ฉฐ

์™€, ์—ฌ๊ธฐ๊นŒ์ง€ ์ฝ์—ˆ๋‹ค๋ฉด ์ •๋ง ๋Œ€๋‹จํ•ด! ๐Ÿ‘ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋กœ ์•ˆ์ „ํ•˜๊ณ  ํ™•์žฅ ๊ฐ€๋Šฅํ•œ ๊ตญ์ œํ™” ์‹œ์Šคํ…œ์„ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์„ ๋‹ค ๋ฐฐ์› ์–ด.

ํ•ต์‹ฌ์„ ์ •๋ฆฌํ•˜๋ฉด:

๐ŸŽ ํ•ต์‹ฌ ์š”์•ฝ 1๏ธโƒฃ ํƒ€์ž… ์•ˆ์ •์„ฑ: ๋ฒˆ์—ญ ํ‚ค์™€ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ํƒ€์ž…์œผ๋กœ ์ •์˜ํ•ด์„œ ์˜ค๋ฅ˜๋ฅผ ์‚ฌ์ „์— ๋ฐฉ์ง€

2๏ธโƒฃ ๊ตฌ์กฐํ™”: ๋„ค์ž„์ŠคํŽ˜์ด์Šค์™€ ๋ชจ๋“ˆํ™”๋กœ ๊ด€๋ฆฌํ•˜๊ธฐ ์‰ฌ์šด ๊ตฌ์กฐ ๋งŒ๋“ค๊ธฐ

3๏ธโƒฃ ์„ฑ๋Šฅ: ์ง€์—ฐ ๋กœ๋”ฉ๊ณผ ์บ์‹ฑ์œผ๋กœ ๋น ๋ฅธ ์‚ฌ์šฉ์ž ๊ฒฝํ—˜ ์ œ๊ณต

4๏ธโƒฃ ํ™•์žฅ์„ฑ: ํ”„๋กœ์ ํŠธ๊ฐ€ ์ปค์ ธ๋„ ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ์‰ฌ์šด ์‹œ์Šคํ…œ ๊ตฌ์ถ•

5๏ธโƒฃ ์ž๋™ํ™”: ํ…Œ์ŠคํŠธ์™€ ๊ฒ€์ฆ์„ ์ž๋™ํ™”ํ•ด์„œ ์‹ค์ˆ˜ ์ค„์ด๊ธฐ

์ฒ˜์Œ์—๋Š” ๋ณต์žกํ•ด ๋ณด์ผ ์ˆ˜ ์žˆ์ง€๋งŒ, ํ•œ ๋ฒˆ ์ œ๋Œ€๋กœ ๊ตฌ์ถ•ํ•ด๋‘๋ฉด ์ •๋ง ํŽธํ•ด. ํŠนํžˆ ๊ธ€๋กœ๋ฒŒ ์„œ๋น„์Šค๋ฅผ ๋งŒ๋“ค ๋•Œ๋Š” ํ•„์ˆ˜์•ผ!

์ด์ œ ๋‹น์‹ ๋„ ์„ธ๊ณ„๋ฅผ ์ƒ๋Œ€๋กœ ์„œ๋น„์Šค๋ฅผ ๋งŒ๋“ค ์ค€๋น„๊ฐ€ ๋์–ด. ํ•œ๊ตญ ์‚ฌ์šฉ์ž๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์ „ ์„ธ๊ณ„ ์‚ฌ๋žŒ๋“ค์ด ๋‹น์‹ ์˜ ์„œ๋น„์Šค๋ฅผ ํŽธํ•˜๊ฒŒ ์“ธ ์ˆ˜ ์žˆ๊ฒŒ ๋˜๋Š” ๊ฑฐ์ง€. ๋ฉ‹์ง€์ง€ ์•Š์•„? ๐ŸŒโœจ

๊ถ๊ธˆํ•œ ์ ์ด ์žˆ๊ฑฐ๋‚˜ ๋ง‰ํžˆ๋Š” ๋ถ€๋ถ„์ด ์žˆ์œผ๋ฉด ์–ธ์ œ๋“  ์ปค๋ฎค๋‹ˆํ‹ฐ์— ๋ฌผ์–ด๋ด. ๊ทธ๋ฆฌ๊ณ  ์‹ค์ œ๋กœ ํ”„๋กœ์ ํŠธ์— ์ ์šฉํ•ด๋ณด๋ฉด์„œ ๋ฐฐ์šฐ๋Š” ๊ฒŒ ๊ฐ€์žฅ ์ข‹์•„. ์ž‘์€ ํ”„๋กœ์ ํŠธ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ ์ ์  ํ™•์žฅํ•ด๋‚˜๊ฐ€๋ด!

ํ™”์ดํŒ…! ๐Ÿš€

๐ŸŒŸ ์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๋‹ค๋ฅธ ๊ฐœ๋ฐœ์ž๋“ค๊ณผ๋„ ๊ณต์œ ํ•ด์ฃผ์„ธ์š”! ๐ŸŒŸ

๋Œ“๊ธ€ ์ž‘์„ฑ

์ด ๊ธ€์— ๋Œ€ํ•œ ์—ฌ๋Ÿฌ๋ถ„์˜ ์ƒ๊ฐ์„ ๋“ค๋ ค์ฃผ์„ธ์š”

๋Œ“๊ธ€ 0
๋Œ“๊ธ€์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘์ž…๋‹ˆ๋‹ค.

์•„์ง ๋Œ“๊ธ€์ด ์—†์Šต๋‹ˆ๋‹ค.