REPO STORY / 레포 이야기
i18next/next-i18next
Next.js 앱을 위한 가장 쉬운 다국어 지원 라이브러리
01 / 뭐 하는 레포인가요?
어떤 일을
도와주나요?
next-i18next는 i18next 위에 만들어진 번역 계층이에요. Next.js의 App Router, Pages Router, 심지어 둘을 함께 쓰는 혼합 환경도 모두 지원합니다. 복잡한 언어 감지와 라우팅 설정은 라이브러리가 자동으로 해주고, 당신은 번역 파일만 준비해서 getT() 또는 useT()로 텍스트를 불러오면 돼요.
- App Router와 Pages Router 양쪽 모두 지원
- 쿠키 및 Accept-Language 기반 자동 언어 감지
- locale-in-path(/en/about) 및 no-locale-path 라우팅 모드
단일 라이브러리로 현대적인 App Router(Server Components), 기존 Pages Router, 혼합 라우터 환경을 모두 지원하는 것이 핵심 차별점입니다.
02 / 내 상황에 맞을까?
이럴 때 써요,
선택 전에 확인해요.
이럴 때 써요
- 글로벌 시장을 대상으로 하는 Next.js SPA/SSR 앱을 빠르게 다국어화하고 싶을 때
- Vercel 같은 서버리스 플랫폼에서 번역 파일을 번들에 포함시켜야 할 때
- 기존 Pages Router 프로젝트를 App Router로 마이그레이션하면서 i18n 설정을 유지하고 싶을 때
이럴 땐 다시 확인해요
아래 준비 조건이 맞지 않으면 먼저 환경을 준비해 주세요.
- Next.js 13.0 이상
- Node.js 16 이상
- 기본 i18next 개념 이해
깃밥 한국어 요약의 활용 예와 준비 조건을 옮겼어요.
03 / 시작하려면
첫 걸음,
차근차근.
준비할 것
- Next.js 13.0 이상
- Node.js 16 이상
- 기본 i18next 개념 이해
- 라이브러리 및 의존성 설치
npm install next-i18next i18next react-i18next
- 번역 파일 생성
mkdir -p app/i18n/locales/en app/i18n/locales/de
각 폴더에 common.json 같은 번역 JSON 파일 생성
- 설정 파일 생성
i18n.config.ts파일을 프로젝트 루트에 생성:
import type { I18nConfig } from 'next-i18next/proxy'
const i18nConfig: I18nConfig = {
supportedLngs: ['en', 'de'],
fallbackLng: 'en',
defaultNS: 'common',
ns: ['common'],
resourceLoader: (language, namespace) =>
import(`./app/i18n/locales/${language}/${namespace}.json`),
}
export default i18nConfig
- 프록시 설정 (Next.js 16+)
proxy.ts를 프로젝트 루트에 생성:
import { createProxy } from 'next-i18next/proxy'
import i18nConfig from './i18n.config'
export const proxy = createProxy(i18nConfig)
export const config = {
matcher: ['/((?!api|_next/static|_next/image|assets|favicon.ico|sw.js|site.webmanifest).*)'],
}
- 루트 레이아웃 설정
app/[lng]/layout.tsx파일:
import { initServerI18next, getT, getResources, generateI18nStaticParams } from 'next-i18next/server'
import { I18nProvider } from 'next-i18next/client'
import i18nConfig from '../../i18n.config'
initServerI18next(i18nConfig)
export async function generateStaticParams() {
return generateI18nStaticParams()
}
export default async function RootLayout({
children,
params,
}: {
children: React.ReactNode
params: Promise<{ lng: string }>
}) {
const { lng } = await params
const { i18n } = await getT()
const resources = getResources(i18n)
return (
<html lang={lng}>
<body>
<I18nProvider language={lng} resources={resources}>
{children}
</I18nProvider>
</body>
</html>
)
}
- 페이지에서 사용
app/[lng]/page.tsx에서:
import { getT } from 'next-i18next/server'
export default async function Home() {
const { t } = await getT('common')
return <h1>{t('title')}</h1>
}
명령은 기존 요약에 적힌 그대로예요. 실행하거나 설치 성공을 검증하지 않았어요. 공식 소요시간 미제시.
04 / 이웃 레포
어떤 레포와 연결될까요?
비교 연결망의 정적 스냅샷 · 관계 종류와 기록된 근거예요. 현재 공개된 레포만 표시해요.
현재 표시할 공개 이웃 레포가 없어요.
비교함에서 연결망 보기 ↗