i18nifty
GitHubHomeSandbox
  • 🏁Quick start
  • 🚄Asynchronous locale resources download
  • 📖API Reference
    • useLang
    • $lang
    • LocalizedString
    • useTranslation
    • getTranslation
  • ⬆️Migration guides
    • ⬆️v2 -> v3
Powered by GitBook
On this page

Was this helpful?

  1. API Reference

$lang

Set the language at any time, from anywhere.

evtLang enable you to switch the language without using useLang that can only be used in a react component.

import { $lang } from "i18n";

setTimeout(
    ()=> {
        console.log(`The app is currently in ${evtLang.state}`);
        console.log("We switch to fr now!");
        //This will trigger components to re-render.
        $lang.current= "fr";
    },
    30_000
);

Have a global callback that is invoked whenever the language is changed.

import { $lang } from "i18n";

evtLang
    .subscribe(lang=> console.log(`The app has just beed switched to ${lang}`));
PrevioususeLangNextLocalizedString

Last updated 1 year ago

Was this helpful?

📖