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.
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
npm install lefineimport { 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',})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')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.
- 01
Install the client
One dependency-free package. It runs in browsers, Node, Deno, Bun and Cloudflare Workers.
terminalbashnpm install lefinenpx lefine loginnpx lefine strings pull -o locales# lefine/strings has no framework dependency.# pull writes locales/en.json, de.json, ... - 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.jsimport { 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',}) - 03
Read a message
getMessages returns a plain nested object, so a four-line lookup helper is the whole runtime you need.
main.jsimport { t } from './i18n.js'document.querySelector('h1').textContent = t('title')// ICU values work too: "Hello, {name}"document.querySelector('p').textContent = t('greeting', { name: 'World' })
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.
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()}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.
// 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)]}`;}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
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.
Reads from the plain object the pulled JSON file already gave.
0 network calls per render
getMessages(locale) — served from the in-memory cache if it is warm.
60 s cache · 0 deps
Cloudflare worker answers from the nearest edge cache.
max-age=60 · never a 5xx
The published translation files the sync worker wrote.
source of truth
- 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
Proposal reviewed in the dashboard, glossary enforced.
MCP · dashboard · CLI
Sync worker writes the locale files to R2.
lefine strings publish
Fire-and-forget purge of the affected keys and the manifest.
non-critical by design
The next getMessages() past the TTL returns the new copy.
~5 min worst case
Related Guides
Start free.
Start JavaScript i18n Today
Manage your JavaScript translations with AI-powered workflows, CLI sync, and edge CDN delivery.