Przejdź do głównej zawartości

API

View .md

Ta treść nie jest jeszcze dostępna w Twoim języku.

Call it once per app or shared package and export the result.

  • languages: every supported language code, as a non-empty array literal.
  • base: the language the source texts are written in (usually 'en'). Must be in languages.
  • current (optional): a function that returns the current language. Only needed for text().

Returns { t, group, text, createUseLang, languages, base }. Pass the whole object to an adapter.

One text. See Texts and Parameters.

Form Key
t('Save', { de: 'Speichern' }) 'Save'
t({ cancel: 'Cancel' }, { de: 'Abbrechen' }) cancel
t((p: P) => string, { de: (p) => string }) property name
t({ key: (p: P) => string }, { ... }) key

Turns texts into an object keyed by base text or custom key. See Groups.

Returns a function that reads the current language when called. See Zod.

Binds a tree to one language. See Reading texts.

Type Meaning
TranslationTree Any object of texts, groups and nested objects.
Translated<T, L> T with every text turned into its string or function type (result of useLang).
UseLang<T, L> Type of the function returned by createUseLang.
Lang<L> What adapters need from a createLang() result.
Text One text in one language: string or TextFn.
TextFn<P> A text with parameters: (params: P) => string.