콘텐츠로 바로 가기
JavaScript i18n

JavaScript i18n: Intl API를 활용한 브라우저 내장 국제화

자바스크립트에는 숫자, 날짜, 목록의 서식을 지정하고 다양한 로케일에 걸쳐 복수형 규칙을 처리하기 위한 내장 표준으로 Intl API가 포함되어 있습니다. 별도의 외부 라이브러리가 필요하지 않습니다. 이 API는 모든 최신 브라우저와 Node.js에서 지원되며, 로케일에 민감한 문자열 비교, 분할 및 상대적 시간 서식 지정을 기본적으로 제공합니다.

Package
lefine/strings
Runs in
Browsers · Node · Deno · Bun · Workers
lefine
01터미널
npm install lefine
02i18n.js
import { createTranslator } from 'lefine/strings'import messages from './locales/en.json' with { type: 'json' }// messages is { namespace: { key: text } }, as pull wrote itexport const t = createTranslator({  locale: 'en',  messages,  namespace: 'home',})
03main.js
import { t } from './i18n.js'document.querySelector('h1').textContent = t('title')// ICU values work too: "Hello, {name}"document.querySelector('p').textContent = t('greeting', { name: 'World' })
t('title')
Welcome
01/Setup

순수 JavaScript에 i18n 세 단계로 추가하기

JavaScript 전용 패키지 설치는 없습니다: @better-i18n/core가 여기 모든 SDK가 감싸는 순수 JavaScript 클라이언트입니다.

  1. 01

    클라이언트 설치하기

    의존성 없는 단일 패키지. 브라우저, Node, Deno, Bun, Cloudflare Workers에서 실행됩니다.

    terminalbash
    npm install lefinenpx lefine loginnpx lefine strings pull -o locales# lefine/strings has no framework dependency.# pull writes locales/en.json, de.json, ...
  2. 02

    클라이언트를 한 번만 생성하기

    모듈 스코프에서 인스턴스를 생성하고 필요한 곳에서 import하세요. 클라이언트 하나, 설정 하나로 모든 호출이 동일한 인메모리 캐시를 공유합니다.

    i18n.js
    import { createTranslator } from 'lefine/strings'import messages from './locales/en.json' with { type: 'json' }// messages is { namespace: { key: text } }, as pull wrote itexport const t = createTranslator({  locale: 'en',  messages,  namespace: 'home',})
  3. 03

    Read a message

    getMessages는 단순 중첩 객체를 반환하므로, 4줄짜리 조회 도우미가 전부 필요한 런타임입니다.

    main.js
    import { t } from './i18n.js'document.querySelector('h1').textContent = t('title')// ICU values work too: "Hello, {name}"document.querySelector('p').textContent = t('greeting', { name: 'World' })
02/Two ways

클라이언트 사용 시, 또는 fetch 사용 시

클라이언트는 캐싱, 재시도, 폴백 체인을 추가합니다. 만약 직접 관리하려면 CDN은 순수 JSON 엔드포인트입니다.

locale.js
import { createTranslator } from 'lefine/strings'let t = createTranslator({ locale: 'en', messages: await load('en'), namespace: 'home' })async function load(locale) {  const res = await fetch(`/locales/${locale}.json`) // the files pull wrote  return res.json()}export async function setLocale(next) {  t = createTranslator({ locale: next, messages: await load(next), namespace: 'home' })  document.documentElement.lang = next  render()}
03/Formatting

JavaScript Intl API 실전

현대 브라우저 또는 Node.js 런타임에서 로케일별 출력을 위해 내장 Intl 생성자를 사용하여 통화, 날짜, 서수를 포맷합니다.

format.js
// Using the built-in Intl APIconst formatter = new Intl.NumberFormat('de-DE', {  style: 'currency',  currency: 'EUR',});console.log(formatter.format(1234.56)); // "1.234,56 €"// Date formattingconst date = new Intl.DateTimeFormat('ja-JP', {  year: 'numeric',  month: 'long',  day: 'numeric',});console.log(date.format(new Date())); // "2026年3月2日"// Pluralizationconst plural = new Intl.PluralRules('en');const suffixes = { one: 'st', two: 'nd', few: 'rd', other: 'th' };function ordinal(n) {  return `${n}${suffixes[plural.select(n)]}`;}
04/Capabilities

JavaScript Intl API 기능

  • 핵심 i18n 작업을 위한 외부 의존성 없는 내장 Intl API
  • 로케일 기반 통화, 백분율, 단위 포맷팅을 위한 Intl.NumberFormat
  • 로케일별 날짜 및 시간 표시 형식을 위한 Intl.DateTimeFormat
  • 100개 이상의 지역 설정을 아우르는 서수 및 기수 복수형에 대한 국제 복수 규칙
  • 복수형, 선택, 중첩을 위한 ICU MessageFormat(Intl에 내장되어 있지 않으며 intl-messageformat 같은 라이브러리를 통해 사용)
  • 사람이 읽기 쉬운 상대 날짜(예: "3일 전")를 위한 Intl.RelativeTimeFormat
  • 로케일을 고려한 결합 및 분리 목록을 위한 Intl.ListFormat
  • 로케일에 민감한 문자열 정렬 및 비교를 위한 Intl.Collator
  • 단어, 문장 및 문소 경계 감지를 위한 국제 세그멘테이션 도구
How it works

JavaScript 문자열의 출처

빌드 단계 없음, 번들된 로케일 파일 없음: 클라이언트가 런타임에 로케일을 결정하고 엣지가 응답합니다.

Read path — every locale load
Your JavaScript app

Reads from the plain object the pulled JSON file already gave.

0 network calls per render

lefine

getMessages(locale) — served from the in-memory cache if it is warm.

60 s cache · 0 deps

CDN edge

Cloudflare worker answers from the nearest edge cache.

max-age=60 · never a 5xx

R2 object store

The published translation files the sync worker wrote.

source of truth

Fallback chain — tried in order when a hop fails
  • 01In-memory TTL cache
  • 02CDN fetch, with timeout and one retry
  • 03Persistent storage, if configured
  • 04staticData bundled with the app
  • 05Throw — after everything above missed
Write path — dashboard to app
AI or translator

Proposal reviewed in the dashboard, glossary enforced.

MCP · dashboard · CLI

Publish

Sync worker writes the locale files to R2.

lefine strings publish

CDN purge

Fire-and-forget purge of the affected keys and the manifest.

non-critical by design

Live in the app

The next getMessages() past the TTL returns the new copy.

~5 min worst case

0dependencies in core
5 minSDK cache in production; edge 60s
200CDN status, even on failure
5fallback layers before an error
Get started

무료로 시작하세요.

지금 바로 JavaScript 국제화(i18n)를 시작하세요

AI 기반 워크플로, CLI 동기화, 엣지 CDN 제공으로 JavaScript 번역을 관리하십시오.