React reference

Ways

Root props

Common root props:

PropTypeNotes
apiKeystringRequired.
localestringCurrent target locale.
baseLocalestringSource locale.
persistLocaleCookiebooleanDefault locale-cookie policy for the root runtime.
contextstring | objectOptional root context.
cacheTtlnumberCache TTL for translation requests.
messageFormatter'waysParser' | 'none' | fnParser or formatter override.
fetchertypeof fetchCustom fetch implementation.
acceptedLocalesstring[]Optional explicit locale list.

Scoped props

Nested scopes accept:

PropTypeNotes
contextstring | objectRequired.
localestringOptional locale override.
baseLocalestringOptional base locale override.
componentsRecord<string, component>Components used inside translatable content.

T

T is the JSX-first translation primitive.

PropTypeNotes
childrenReactNodeRequired.
varsRecord<string, unknown>Interpolation input.
contextstring | objectOptional leaf context override.
componentsRecord<string, component>Component mapping for rich content.
fixedbooleanSkip translation for fixed branding-like content.

useT()

useT() returns a translation function for strings, attributes, and logic.

tsx
const t = useT();
const label = t('Save changes');

Runtime hooks

useTranslatedMemo()

A memoized value that recomputes when translations change.

useTranslationLoading()

Returns true while the current context is still loading.

useCurrentLocale()

Reads the root runtime locale.

useSetCurrentLocale()

Returns the setter for the root runtime locale.

LanguageSwitcher

Common props:

PropTypeNotes
currentLocalestringControlled locale.
onLocaleChange(locale) => voidChange handler.
direction'up' | 'down'Menu direction.
styles / classNamesobjectStyling overrides.
unstyledbooleanDisable built-in styles.

Utility exports

@18ways/react also re-exports:

  • fetchAcceptedLocales
  • fetchEnabledLanguages
  • resolveOrigin