web-i18n API Reference

Imported from @opentf/web-i18n. Pairs with the locale-routing exports in @opentf/web.

createI18n(options)

OptionTypeDescription
localesstring[]Supported locales. Defaults to the keys of messages.
defaultLocalestringFallback locale. Defaults to the first locale.
messagesRecord<string, Catalog>Eager per-locale catalogs — message id → ICU string (nested objects allowed; keys may be dotted).
load(locale) => Promise<Catalog>Lazy loader for code-split catalogs; populate with loadLocale.

Registers the app's catalogs (call once, near the entry). Returns the store.

t(key, values?)

Translate key for the active locale, formatting values with ICU MessageFormat (interpolation, plural, select, number/date skeletons). Reactive — used in markup it re-renders on a locale change. Fallback chain: active locale → default locale → the raw key.

JSX
t("greeting", { name: "Ada" });   // "Hello, Ada" / "Bonjour, Ada"
t("cart.items", { count });        // ICU plural
ParamTypeDescription
keystringMessage id (flat or dotted-nested).
valuesobjectICU arguments (interpolation, plural counts, select branches).

<T id values />

Component sugar over t() — renders the translation into a <span>. For messages that interpolate a signal, prefer the bare {t("key", { count })} form so the compiler tracks the signal directly.

PropTypeDescription
idstringMessage key.
valuesobjectICU arguments.

fmt

Locale-aware formatters over the native Intl APIs. Each reads the active locale (so it's reactive) and memoizes the underlying Intl.* instance per (locale, options). No catalog required.

MethodBacked byExample (en-US)
fmt.number(value, options?)Intl.NumberFormat1,234.5
fmt.currency(value, currency, options?)Intl.NumberFormat$42.00
fmt.percent(value, options?)Intl.NumberFormat42%
fmt.date(value, options?)Intl.DateTimeFormatJanuary 9, 2026
fmt.relativeTime(value, unit, options?)Intl.RelativeTimeFormat3 days ago
fmt.plural(value, options?)Intl.PluralRules"other"
fmt.list(values, options?)Intl.ListFormata, b, and c

options is passed straight to the underlying Intl constructor.

Locale helpers

ExportSignatureDescription
getLocale()() => stringThe active locale: router.locale → default → "en". Store-independent (works without createI18n).
locales()() => { locales, defaultLocale } | nullThe configured locales, or null before createI18n.
loadLocale(locale)(string) => Promise<void>Load + cache a locale's catalog via the registered load (SSR preload / code-split). No-op if already loaded.
setCatalog(locale, catalog)(string, Catalog) => voidSet a locale's catalog directly (SSR preload / tests).

Locale routing

URL path-prefix routing lives in the core router, not this package — see router.locale, localizePath, setLocale, configureI18n and the Locale Routing guide.