Package APIs
@i18n-micro/runtime
Exported API of @i18n-micro/runtime, generated from the source.
Framework-agnostic i18n runtime for vanilla TypeScript/JavaScript (browser and Node).
import { … } from '@i18n-micro/runtime'
Functions
createI18n
function createI18n(options: I18nOptions): I18n
See I18nOptions · I18n
fetchJsonTranslations
Fetch a JSON translation document from a URL (browser or any fetch-capable runtime).
function fetchJsonTranslations(url: string, init?: RequestInit): Promise<Translations>
See Translations
Classes
I18n
class I18n extends BaseI18n {
constructor(options: I18nOptions)
}
protected readonly ownStore
ReactiveI18nStore
storage
TranslationStorage
The chunks of this instance. Handing them out detaches a fork: what the caller does with them stays here.
protected store
ReactiveI18nStore
The locale, fallback and route state in force. An adapter with per-request state answers its own.
fork
(locale: string = this.getLocale()) => this
A cheap instance for one request or task: own locale, fallback and route, the same dictionaries,
formatters and rules. It sees writes to the parent until its first own write; its writes stay in it.
Forking a fork counts as that fork's first write.
subscribe
(listener: () => void) => () => void
getSnapshot
() => string
locale
string
fallbackLocale
string
currentRoute
string
setRoute
(routeName: string) => void
getLocale
() => string
getFallbackLocale
() => string
getRoute
() => string
loadMessages
(messages?: Record<string, Translations>, routeMessages?: Record<string, Record<string, Translations>>) => void
Load root and optional route-scoped translation maps into the instance. A route chunk holds
the route's own keys; root keys resolve from the root chunk (also ones added later).
addLocaleIso
(localeIso: Record<string, string>, notify = true) => void
Text on screen follows a new plural tag. A render passes
notify: false: it must not wake other components.loadFromUrl
(url: string, options: LoadFromUrlOptions = {}) => Promise<void>
loadFromUrls
(entries: LoadFromUrlEntry[]) => Promise<void>
All or nothing: a failed fetch leaves the dictionaries as they were. Merged in entry order.
addTranslations
(locale: string, translations: Translations, merge = true) => void
addRouteTranslations
(locale: string, routeName: string, translations: Translations, merge = true) => void
hasTranslation
(key: TranslationKey) => boolean
clear
() => void
protected onTranslationsChanged
(locale?: string) => void
Called after every write (load, merge, set, clear): the one place adapters bump their reactivity.
locale is set when one locale's chunk was written, unset when anything may have changed.See BaseI18n · I18nOptions
Types
I18nOptions
interface I18nOptions
locale
string required
fallbackLocale
string
messages
Record<string, Translations>
Root translations keyed by locale code.
routeMessages
Record<string, Record<string, Translations>>
Route-specific translations: routeName → locale → messages.
plural
PluralFunc
missingWarn
boolean
missingHandler
(locale: string, key: string, routeName: string) => void
numberFormats
NumberFormatsConfig
Named number formats per locale (
tn(n, 'currency')).datetimeFormats
DateTimeFormatsConfig
Named datetime formats per locale (
td(d, 'short')).timeZone
string
IANA zone for dates (
Europe/Berlin): set it so server and browser render one date.now
() => number
The clock of relative dates: hand hydration the server's time so both render one text.
localeIso
Record<string, string>
BCP 47 tag per locale code (
iso), for a code that is no language tag: ua → uk-UA. localeIsoMap(locales) builds it.parent
I18n
Set by
fork(): the instance whose dictionaries, formatters and rules this one shares.LoadFromUrlEntry
interface LoadFromUrlEntry extends LoadFromUrlOptions
url
string required
locale
string required
LoadFromUrlOptions
interface LoadFromUrlOptions
locale
string
routeName
string
init
RequestInit
Re-exports
Declared in another package of this repository and documented on its page.
- From
@i18n-micro/core:interpolate·localeIsoMap·FormatService·TranslationStorage - From
@i18n-micro/types:CleanTranslation·Getter·Locale·LocaleCode·Params·PluralFunc·Translations
Generated from the TypeScript sources and their JSDoc by pnpm run docs:generate.
Back to all packages · Integration guides