API
このコンテンツはまだ日本語訳がありません。
createLang({ base, languages, current? })
Section titled “createLang({ base, languages, current? })”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 inlanguages.current(optional): a function that returns the current language. Only needed fortext().
Returns { t, group, text, createUseLang, languages, base }. Pass the whole object to an adapter.
t(baseText, otherLanguages)
Section titled “t(baseText, otherLanguages)”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 |
group(...items)
Section titled “group(...items)”Turns texts into an object keyed by base text or custom key. See Groups.
text(translation)
Section titled “text(translation)”Returns a function that reads the current language when called. See Zod.
createUseLang(language, translations)
Section titled “createUseLang(language, translations)”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. |