ReactNativeLocalization
ReactNativeLocalization copied to clipboard
setLanguage() only change language for current component
Hi, I know that is not specially a BUG, but it's really annoying.
After setLanguage() only change in the current component, and in the others when they update / render next time. What I do, is store the new language key on AsyncStorage and on the file App.js I set the language previously stored. And that works fine. But, I would like that when the user change the language, the whole app refresh that strings without restarting the app. I use Redux in my app.
How I can achieve that changes are applied without force to restart the App?
Thanks.
A workaround I did was setting a key "language" on redux store and importing it on all components and that produces a rerender, or directly forcing update with this.forceUpdate().
Hello, by the mechanism of react-native-localization. strings.key is just return a getter to get localized string. So, it not depend on any render flow, and your change will not affect still component re-rendering.
You can write a custom Text component which have a props from redux statenamedlocale. So whenever your locale` change. It will re-render your CustomText components
You can write a custom
Text component which have a props fromredux statenamedlocale. So whenever yourlocale` change. It will re-render your CustomText components
Can you show me how to do this? My text component is getting re rendered but it is still not changing the locale.
I solved it by creating a Localization Provider and using context hooks. More info here.
I think this is the more convenient way to do this.