loadLocale

loadLocale(locale?, scope?) triggers message loading for a runtime.

It never changes runtime.locale by itself. It only fetches and stores messages.

ts
1import { initIntl, loadLocale } from '@beforesemicolon/intl'2 3initIntl({4  locale: 'en-US',5  srcDir: '/locales',6})7 8await loadLocale() // loads en-US (and fallback locale if needed)

Signature

ts
1function loadLocale(locale?: string, scope?: IntlRuntime): Promise<IntlRuntimeSnapshot>

Preload and warm cache

ts
1const runtime = initIntl({ locale: 'en-US', srcDir: '/locales' })2await loadLocale('fr-FR', runtime) // preload3await loadLocale('es-ES', runtime) // preload another one

Preloading keeps a second locale ready for quick switching while keeping current runtime locale unchanged.

Error handling

ts
1const snapshot = await loadLocale('es-ES')2if (snapshot.status === 'error') {3  console.error(snapshot.error)4}

snapshot.error is populated when fetch fails or parsing fails.

Native reference: `fetch`, AbortController

edit this doc