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() निचले-स्तर की runtime state machine को expose करता है। store locale state, config, hydrated translations, याद रखे गए source strings, और blocking loading state का मालिक होता है।

आम methods:

MethodNotes
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

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.

भाषा बदली जा रही है
Vanilla JS संदर्भ