javascript - The component is no Updating -


i'm working on i18n , button changes language spanish english , vice versa.

i have part of code before de reactdom.render works properly:

function tooglelang(){   if(localstorage["lang"]==="es"){     i18nconfig.messages=spanishmessages.messages;     i18nconfig.locale="es"   }   else if(localstorage["lang"]==="en"){     i18nconfig.locale="en"     i18nconfig.messages=englishmessages.messages   }     console.log(localstorage["lang"])     console.log(i18nconfig.messages) } console.log(tooglelang)  reactdom.render(    <intlprovider messages={i18nconfig.messages} locale={i18nconfig.locale}>          <app app={tooglelang.bind(this)}/>     </intlprovider>,     document.getelementbyid('root')   ); 

in app.js have inside component:

onchangelanguage(lang){    /* switch (lang) {         case 'es': i18nconfig.messages = spanishmessages.messages; localstorage.setitem("lang", "es" ); break;         case 'en': i18nconfig.messages = englishmessages.messages; localstorage.setitem("lang", "en" ); break;         default: i18nconfig.messages = spanishmessages.messages; break;     }     this.setstate({  });     i18nconfig.locale = lang;*/     if(lang==="es"){       localstorage.setitem("lang", "es" )     }     else if(lang==="en"){       localstorage.setitem("lang", "en" )      }     console.log(localstorage["lang"])     console.log(this.props.app)     }   onchange(lang){     this.onchangelanguage(lang)     this.props.app()     this.forceupdate()    } 

so when click on button should change language doesn't.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -