docs

React API

LocaleProvider

Required: projectId, environment, initialLocale, fallbackLocale, and children. Optional inputs include publishableKey, catalogs, catalogEndpoint, cookieName, onDiagnostic, availableLocales, syncLocalePreference, and hydrationState.

useTranslation()

Returns:

  • locale, sourceLocale, ready, and sampled diagnostics.
  • async setLocale(locale).
  • t(source, values?, options?).
  • lower-level translate(id, source, values?, components?).
  • availableLocales.

It throws when called outside LocaleProvider.

Explicit components

<T> accepts id?, required defaultMessage, values?, components?, and context?. MessageComponents maps tag names to React elements or chunk functions.

Locale controls

useLocaleOptions(query?) returns filtered, display-name-sorted options with locale, readiness, and setter. LanguageSelector supplies a searchable input and accessible select.

Catalog and preference helpers

  • loadCatalog(input) fetches, parses, verifies integrity, and checks scope.
  • persistLocalePreference(locale, cookieName?, target?) writes the first-party locale cookie.
  • createHydrationState(locale, catalogs) validates and serializes initial state.
  • resolveLocale(input) implements override, user preference, cookie, browser language, and default precedence.

Diagnostics

DiagnosticEvent.code is missing-translation, invalid-translation, or catalog-load-failed, with locale, message, and optional message ID.

See also

Show translated content · Integration testing

Did this page get you to a working result?

On this page

No Headings