getIntl

getIntl(scope?) gives you the runtime instance that formatters and components use.

Use it when you need to inspect current state, read messages directly, or share one runtime instance between modules.

ts
1import { getIntl } from '@beforesemicolon/intl'2 3const runtime = getIntl()4console.log(runtime.locale)5console.log(runtime.direction)6console.log(runtime.snapshot().loadedLocales)

Signature

ts
1function getIntl(scope?: IntlRuntime): IntlRuntime

How it chooses scope

ts
1const shared = getIntl()2const local = getIntl(customRuntime)

Snapshot pattern

snapshot() is the fastest way to read runtime status without triggering UI behavior.

ts
1const snapshot = getIntl().snapshot()2 3console.log(snapshot.locale) // active locale4console.log(snapshot.status) // 'idle' | 'loading' | 'ready' | 'error'5console.log(snapshot.parentScope?.locale) // inherited scope when nested6console.log(snapshot.loadedLocales) // locales already loaded in this runtime

Message lookup and formatting without side effects

Runtime access gives you deterministic behavior in tests and reusable helpers.

ts
1import { initIntl, getIntl, intlMsg } from '@beforesemicolon/intl'2 3initIntl({ locale: 'fr-FR', messages: { product: { title: 'Produit' } } })4const runtime = getIntl()5const title = runtime.getMessage('product.title')6const rendered = intlMsg('product.title', undefined, { scope: runtime })

Component interop

Components use nearest <intl-locale> and then default runtime. If you need exact parity in custom JS, use the same scoped runtime you pass to components.

getIntl() itself is safe for plain runtime reads but does not subscribe to updates.

edit this doc