Skip to content
JavaScript i18n

JavaScript i18n: Browser-Native Internationalization with the Intl API

JavaScript includes the Intl API as a built-in standard for formatting numbers, dates, lists, and handling pluralization rules across locales.

Package
lefine/strings
Runs in
Browsers · Node · Deno · Bun · Workers
lefine
01Terminal
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/Overview

No external libraries required. The API is supported in all modern browsers and Node.js, providing locale-sensitive string comparison, segmentation, and relative time formatting out of the box.

02/Setup

Add i18n to plain JavaScript in three steps

There is no JavaScript-specific package to install: @better-i18n/core is the plain-JavaScript client every other SDK here wraps.

  1. 01

    Install the client

    One dependency-free package. It runs in browsers, Node, Deno, Bun and 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

    Create the client once

    Instantiate at module scope and import it wherever you need it: one client, one config, and every call shares the same in-memory cache.

    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 returns a plain nested object, so a four-line lookup helper is the whole runtime you need.

    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' })
03/Two ways

With the client, or with fetch

The client adds caching, retries and the fallback chain. If you would rather own that yourself, the CDN is a plain JSON endpoint.

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()}
04/Formatting

JavaScript Intl API in Practice

Format currencies, dates, and ordinals using built-in Intl constructors with locale-specific output in any modern browser or Node.js runtime.

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)]}`;}
05/Capabilities

JavaScript Intl API Features

  • Built-in Intl API with no external dependencies for core i18n operations
  • Intl.NumberFormat for locale-aware currency, percent, and unit formatting
  • Intl.DateTimeFormat for locale-specific date and time display patterns
  • Intl.PluralRules for ordinal and cardinal pluralization across 100+ locales
  • ICU MessageFormat for plurals, selects and nesting, via a library such as intl-messageformat (not built into Intl)
  • Intl.RelativeTimeFormat for human-readable relative dates (e.g., "3 days ago")
  • Intl.ListFormat for locale-aware conjunction and disjunction lists
  • Intl.Collator for locale-sensitive string sorting and comparison
  • Intl.Segmenter for word, sentence, and grapheme boundary detection
How it works

Where a JavaScript string comes from

No build step and no bundled locale files: the client resolves a locale at runtime and the edge answers it.

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

Start free.

Start JavaScript i18n Today

Manage your JavaScript translations with AI-powered workflows, CLI sync, and edge CDN delivery.