Vanilla JS reference
create18waysEngine(options)
Mag-import mula sa @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
Ibinubunyag ng engine.getStore() ang mas mababang-level na runtime state machine. Ang store ang may-ari ng locale state,
config, hydrated translations, naaalalang source strings, at blocking loading state.
Mga karaniwang paraan:
| Paraan | Notes |
|---|---|
getState() | Basahin ang kasalukuyang napiling locale, settled locale, config, at naka-cache na translations. |
hydrate(input) | Pagsamahin ang mga translation at config sa store. Kapaki-pakinabang para sa SSR o custom bootstrapping. |
dehydrate() | I-snapshot ang store bilang hydration payload na madaling i-merge. |
loadConfig() | Kunín ang tinatanggap na mga locale at fallback config nang minsanan, saka i-cache ang resulta. |
setLocale(locale) | Simulan ang paglipat ng locale sa loob ng store. |
getTranslationSync(input) | Sabay na pag-read na nagbabalik ng handa nang value o isang nakabinbing read na may fallback value. |
getTranslation(input) | Async na pag-read ng translation na nagre-resolve sa panghuling naisaling string. |
isLoading(input?) | Nagbabalik ng true kapag may nakabinbing blocking translation work pa, sa buong app o para sa isang context. |
waitForIdle(input?) | Nagre-resolve kapag naayos na ang blocking translation work. Mag-pass ng timeoutMs para tumigil sa paghihintay pagkalipas ng takdang oras habang ang paglo-load ay nagpapatuloy sa background. |
getIdleState(input?) | Nagbabalik ng timed wait state na pag-aari ng store at ginagamit ng mga renderer: {timedOut, promise}. |
mount(entry) / unmount(entry) | Opsyonal na pagsubaybay sa mount para sa mga integrasyon na nagpapagana ng garbage collection na aware sa mount. |
Kung direktang gumagamit ka ng @18ways/core, karaniwan ay mananatili ka sa antas ng engine.t(...). Lumapit sa
store kapag gumagawa ka ng sarili mong rendering runtime o hydration layer.
mga option ng t()
| 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 na input para sa 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.