Skip to content

is there way to access current language #9

@shootermv

Description

@shootermv

Im trying to create language switch menu. It should display all available languages and the selected one. So far i managed to do the following:

    import {reactTranslateChangeLanguage} from 'translate-components'

   const LangOptions = () => {
      const [currLang, setCurrLang] = useState('he');
      return (
        <div className="lang-options">
           {currLang}
          <div className="lang-drop-menu">
              <button onClick={() => { reactTranslateChangeLanguage('he'); setCurrLang('he'); }}>
                He
               </button>
               <button onClick={() => { reactTranslateChangeLanguage('en'); setCurrLang('en'); }}>
                En
               </button>
           </div>
       </div>
     );
    };

as you can see - im show selected language from hardcoded state ('he').
Im sure there is way to access "defaultLanguage" property of TranslateProvider , but i didnt figured how to do it from docs.
I will very appreciate your help

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions