Vanilla JS reference

create18waysEngine(options)

Import from @18ways/core/engine.

ts
import { create18waysEngine } from '@18ways/core/engine';

Common options:

OptionTypeNotes
apiKeystringRequired.
baseLocalestringSource locale.
localestringCurrent target locale.
contextstring | objectDefault context key.
initialTranslationsTranslationsOptional starting cache.
apiUrlstringOptional API base override.
fetchertypeof fetchCustom fetch implementation.
cacheTtlSecondsnumberRequest cache TTL.
originstringOrigin 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:

MethodNotes
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

OptionTypeNotes
localestringOverride the target locale for this call.
baseLocalestringOverride the base locale for this call.
contextstring | objectOverride the context for this call.
varsRecord<string, unknown>Variable input for waysParser.

Utility exports

The core package also exports lower-level helpers such as:

  • fetchAcceptedLocales
  • fetchConfig
  • locale utilities

Use those when you need them, but the engine should be the default starting point.