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() निचले-स्तर की runtime state machine को expose करता है। store locale state, config, hydrated translations, याद रखे गए source strings, और blocking loading state का मालिक होता है।
आम methods:
| Method | Notes |
|---|---|
getState() | वर्तमान selected locale, settled locale, config, और cached translations पढ़ता है। |
hydrate(input) | translations और config को store में merge करें। SSR या custom bootstrapping के लिए उपयोगी। |
dehydrate() | store को merge-friendly hydration payload में snapshot करें। |
loadConfig() | accepted locales और fallback config को एक बार fetch करें, फिर परिणाम cache करें। |
setLocale(locale) | Start a locale transition inside the store. |
getTranslationSync(input) | एक synchronous read जो या तो ready value लौटाता है या fallback value के साथ एक pending read। |
getTranslation(input) | अंतिम अनुवादित string पर resolve होने वाली async translation read। |
isLoading(input?) | जब ब्लॉकिंग translation work अभी भी लंबित हो, वैश्विक रूप से या किसी एक context के लिए, तो true लौटाता है। |
waitForIdle(input?) | जब ब्लॉकिंग translation work स्थिर हो जाए, तब resolve होता है। लोडिंग बैकग्राउंड में जारी रहते हुए, एक deadline के बाद प्रतीक्षा बंद करने के लिए timeoutMs पास करें। |
getIdleState(input?) | renderer द्वारा उपयोग की जाने वाली store-स्वामित्व वाली timed wait state लौटाता है: {timedOut, promise}. |
mount(entry) / unmount(entry) | Optional mount tracking for integrations that enable mount-aware garbage collection. |
अगर आप सीधे @18ways/core का उपयोग कर रहे हैं, तो आप आम तौर पर engine.t(...) स्तर पर ही रहते हैं। जब आप अपना rendering runtime या hydration layer बना रहे हों, तब store की ओर जाएँ।
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.