πŸ“šΒ Reference


πŸ“œΒ Chapter


i18next-fs-backend

i18next-http-backend

i18next-chained-backend


νŠΉμ§•


  1. 닀쀑 λ°±μ—”λ“œ λ‘œλ”©: ν•˜λ‚˜μ˜ λ°±μ—”λ“œκ°€ μ‹€νŒ¨ν•˜κ±°λ‚˜ νŠΉμ • μ‘°κ±΄μ—μ„œλ§Œ μž‘λ™ν•  λ•Œ λ‹€λ₯Έ λ°±μ—”λ“œλ‘œ λŒ€μ²΄ν•  수 μžˆλ‹€.
  2. ν•˜μ΄λΈŒλ¦¬λ“œ λ‘œλ”© μ „λž΅: 둜컬 파일 μ‹œμŠ€ν…œ(i18next-fs-backend)κ³Ό HTTP μš”μ²­(i18next-http-backend)을 μ‘°ν•©ν•˜μ—¬ μ‚¬μš©ν•  λ•Œ μœ μš©ν•˜λ‹€. 예λ₯Ό λ“€μ–΄, 개발 ν™˜κ²½μ—μ„œλŠ” 둜컬 νŒŒμΌμ„ μ‚¬μš©ν•˜κ³ , ν”„λ‘œλ•μ…˜ ν™˜κ²½μ—μ„œλŠ” CDNμ—μ„œ λ²ˆμ—­ νŒŒμΌμ„ λΆˆλŸ¬μ˜€λ„λ‘ μ„€μ •ν•  수 μžˆλ‹€.
  3. μ„±λŠ₯ μ΅œμ ν™”: μ„œλ²„μ—μ„œ 미리 λ²ˆμ—­ νŒŒμΌμ„ λ‘œλ“œν•΄λ‘” ν›„(캐싱), ν΄λΌμ΄μ–ΈνŠΈμ—μ„œλŠ” ν•„μš” μ‹œμ—λ§Œ λ™μ μœΌλ‘œ HTTP μš”μ²­μ„ λ³΄λ‚΄λŠ” ν•˜μ΄λΈŒλ¦¬λ“œ μ „λž΅μ— ν™œμš©λœλ‹€.

μ˜ˆμ‹œ


// i18n.js λ˜λŠ” i18next μ„€μ • 파일
import i18n from 'i18next';
import ChainedBackend from 'i18next-chained-backend';
import FSBackend from 'i18next-fs-backend';
import HttpBackend from 'i18next-http-backend';

const isServer = typeof window === 'undefined';

i18n
  .use(ChainedBackend)
  .init({
    // ...기타 μ„€μ • (lng, fallbackLng λ“±)
    backend: {
      backends: isServer ? [FSBackend] : [HttpBackend],
      backendOptions: [
        {
          // FSBackend μ˜΅μ…˜: μ„œλ²„μ—μ„œ 파일 경둜 μ§€μ •
          loadPath: 'public/locales/{{lng}}/{{ns}}.json',
        },
        {
          // HttpBackend μ˜΅μ…˜: ν΄λΌμ΄μ–ΈνŠΈμ—μ„œ HTTP 경둜 μ§€μ •
          loadPath: '/locales/{{lng}}/{{ns}}.json',
        },
      ],
    },
  });