Vanilla JS reference
create18waysEngine(options)
Import from @18ways/core/engine.
import { create18waysEngine } from '@18ways/core/engine';Common options:
| Option | Type | Notes |
|---|---|---|
apiKey | string | Required. |
baseLocale | string | Source locale. |
locale | string | Current target locale. |
context | string | object | Default context key. |
initialTranslations | Translations | Optional starting cache. |
apiUrl | string | Optional API base override. |
fetcher | typeof fetch | Custom fetch implementation. |
cacheTtlSeconds | number | Request cache TTL. |
origin | string | Origin forwarded on server-side requests. |
Engine methods
t(text, options?)
Translate a string and return the resolved value.
setLocale(locale)
Change the target locale.
getLocale()
Read the current target locale.
getStore()
Access the underlying translation store.
TranslationStore
engine.getStore() exposes the lower-level runtime state machine. The store owns locale state,
config, hydrated translations, remembered source strings, and blocking loading state.
Common methods:
| Method | Notes |
|---|---|
getState() | Read the current selected locale, settled locale, config, and cached translations. |
hydrate(input) | Merge translations and config into the store. Useful for SSR or custom bootstrapping. |
dehydrate() | Snapshot the store into a merge-friendly hydration payload. |
loadConfig() | Fetch accepted locales and fallback config once, then cache the result. |
setLocale(locale) | Start a locale transition inside the store. |
getTranslationSync(input) | Synchronous read that returns either a ready value or a pending read with a fallback value. |
getTranslation(input) | Async translation read that resolves to the final translated string. |
isLoading(input?) | Returns true when blocking translation work is still pending, globally or for one context. |
waitForIdle(input?) | Resolves when blocking translation work settles. Pass timeoutMs to stop waiting after a deadline while loading continues in the background. |
getIdleState(input?) | Returns the store-owned timed wait state used by renderers: {timedOut, promise}. |
mount(entry) / unmount(entry) | Optional mount tracking for integrations that enable mount-aware garbage collection. |
If you are using @18ways/core directly, you usually stay at the engine.t(...) level. Reach for
the store when you are building your own rendering runtime or hydration layer.
t() options
| Option | Type | Notes |
|---|---|---|
locale | string | Override the target locale for this call. |
baseLocale | string | Override the base locale for this call. |
context | string | object | Override the context for this call. |
vars | Record<string, unknown> | Variable input for waysParser. |
Utility exports
The core package also exports lower-level helpers such as:
fetchAcceptedLocalesfetchConfig- locale utilities
Use those when you need them, but the engine should be the default starting point.