ReactNativeLocalization
ReactNativeLocalization copied to clipboard
setLaguage return undefined and doesn't switch language
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.