AlexanderZaytsev / react-native-i18n

React Native + i18n.js
MIT License
2.18k stars 491 forks source link

locale.split is not a functi on. (In 'locale.split("-")', 'locale.split' is undefined) #275

Open abdulkabirpatel opened 3 years ago

abdulkabirpatel commented 3 years ago

I am getting error [Thu Dec 10 2020 23:42:05.669] ERROR TypeError: locale.split is not a functi on. (In 'locale.split("-")', 'locale.split' is undefined)

whenever I add

const langCheck=async()=>{

const languageCode = await AsyncStorage.getItem(language);

I18n.locale = languageCode; }

navidabasi commented 2 years ago

maybe try to change it to this I18n.locale = languageCode.toString() I think you are sending a non-string value to a function that only accepts strings if my fix didn't work you can pass your asyncStorage value to a function and then make it a string, then pass it to a state then use it in I18n.locale. Also if you are using the i18njs library it's i18n.locale not I18n.locale