stefalda / ReactNativeLocalization

Class to localize the ReactNative interface

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

setLaguage return undefined and doesn't switch language

fouad1994 opened this issue · comments

i have these libraries:
"react": "16.8.6",
"react-native": "0.60.4",
"react-native-localization": "^2.1.5",

this is the code:

this.languages = new LocalizedStrings({ "en-US":{ how:"How do you want your egg today?", boiledEgg:"Boiled egg", softBoiledEgg:"Soft-boiled egg", choice:"How to choose the egg" }, en:{ how:"How do you want your egg today?", boiledEgg:"Boiled egg", softBoiledEgg:"Soft-boiled egg", choice:"How to choose the egg" }, ar: { how:"Come vuoi il tuo uovo oggi?", boiledEgg:"Uovo sodo", softBoiledEgg:"Uovo alla coque", choice:"Come scegliere l'uovo" } });

this.languages.how //return "How do you want your egg today?"

but

languages.setLanguage('en-US') //return undefined
languages.setLanguage('en') //return undefined
languages.setLanguage('ar') //return undefined

That’s correct. SetLanguage has no return value. You should then use the string key to return the translation...

I think you need to re-render state:

handleSetLanguage = key => {
    strings.setLanguage(key);
    this.setState({}); <--
};

HeroSony please explain!
why use this statement ' this.setState({}); <-- ' ?

@minhtet7674 because this.setState will reload the whole component.