Reading texts
Ta treść nie jest jeszcze dostępna w Twoim języku.
createUseLang(language, translations)
Section titled “createUseLang(language, translations)”Binds a translation tree to one language and returns useLang:
const useLang = createUseLang('de', translations)useLang() // the whole tree in GermanuseLang((all) => all.login) // only the `login` subtreelanguagemust be one oflanguages(a type error, and a runtime error for unknown values).- The scope function must return a subtree (an object), not a single text. Read single texts from the result:
useLang((all) => all.login).title. - Results are cached per subtree and language and frozen. Calling
useLangagain returns the same object, so it is cheap to call often and safe as a React dependency.
createUseLang has a fixed language. To switch languages at runtime, call it again with the new language, or use an adapter: