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

useLang

Hook for changing the currently active language.

//This is the custom useLang, generated and exported by 
//you sin the src/i18n.tsx filed.
import { useLang } from "i18n";

function MyComponent(){

    const { lang, setLang } = useLang();
      
    return (
        <>
            <span>The app is currently in {(()=>{
                switch(lang){
                    case "en": return "English";
                    case "fr": return "French";
                }
            })()}</span>
            <button onClick={()=> setLang("en")}>Put the app in English</button>
            <button onClick={()=> setLang("fr")}>Put the app in French</button>
        </>
    );
    
}

PreviousAsynchronous locale resources downloadNext$lang

Last updated 1 year ago

Was this helpful?

📖