Server-Side i18n
Hono, Express, 엣지를 위한 서버 사이드 i18n
API와 서버에서 렌더링되는 앱을 국제화하세요. Better I18N은 자동 로케일 감지와 함께 Hono, Express, Fastify, 엣지 런타임용 미들웨어를 제공합니다.
Setup
Set up in 3 steps
Install the package
@better-i18n/server를 설치하세요. 사용하는 프레임워크에 따라 Hono 또는 Express를 선택적으로 설치합니다.
terminal
npm install @better-i18n/server
# Hono: npm install hono
# Express: npm install expressCreate a singleton
createServerI18n()을 모듈 스코프에서 한 번만 인스턴스화하세요. TtlCache는 모든 요청이 공유하므로 요청마다 CDN을 호출하지 않습니다.
i18n.ts
import { createServerI18n } from '@better-i18n/server';
export const i18n = createServerI18n({
projectId: 'your-org/your-api',
defaultLocale: 'en',
});Register middleware
사용하는 프레임워크에 미들웨어를 연결하세요. 미들웨어는 Accept-Language를 읽어 로케일을 확인하고 요청 컨텍스트에 t()를 주입합니다.
Example
Framework middleware
서버 프레임워크를 선택하세요 — 미들웨어 API는 Hono와 Node.js 어댑터에서 동일합니다.
app.ts
import { Hono } from 'hono';
import { betterI18n } from '@better-i18n/server/hono';
import { i18n } from './i18n';
type Variables = { locale: string; t: Translator };
const app = new Hono<{ Variables: Variables }>();
app.use('*', betterI18n(i18n));
app.get('/api/users/:id', (c) => {
const t = c.get('t');
return c.json({ error: t('errors.notFound') }, 404);
});Capabilities
서버에서 Better I18N을 사용하는 이유
웹 표준 미들웨어 — Hono, Cloudflare Workers, Deno Deploy
Node.js 어댑터 — fromNodeHeaders()를 통한 Express, Fastify, Koa 지원
자동 Accept-Language — RFC 5646을 준수하는 로케일 감지
싱글턴 TtlCache — 워밍업 이후에는 요청마다 CDN을 호출하지 않습니다
타입 안전한 t() — 번역 키에 대한 완전한 TypeScript 추론
엣지 대응 — Cloudflare Workers 기본 지원
Other frameworks
Get started
지금 API 응답을 현지화하세요
번역된 오류 메시지, 알림, 콘텐츠를 오버헤드 없이 백엔드에서 제공하세요.