简体   繁体   中英

Changing the devise locale in React-native

I have successfully installed react-native-i18n and its works fine. However, I want to change the locale inside the React native app itself.

I have added a button( Touchable opacity ) and have written the following code :

onPress={() => { i18n.locale = 'ar'; }}

However, this does not change the locale to 'ar' and all my translations are still coming for english ( en-US ) only. I dont want the user to go to phone settings and change the locale from there. Can I not do it from the app itself? Only so that the locale is limited for my app only.

You need to rerender the app. Listen for ConfigurationChange event to rerender or you may refer this GitHub issue . Easier hack is to set a state once you do i18n.locale = 'ar' :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM