I have this problem only when using EXPO (ios, android). When building with Xcode - don't have this problem.
Error in this line
I18nJs.locale = RNI18n.languages[0];
export const getLanguages = RNI18n.getLanguages;
I commented this lines and add I18nJs.locale = 'en'; this help but not resolves the issue.
I used react-native default pack and add EXPO
Happens to me as well, works fine on iOS but fails in Android, I followed the Android setup guide to no avail
same problem here, works on ios but not on android.
+1
If you are using Expo, please consider using getCurrentLocaleAsync() and the i18n lib of your choice (i18n-js if you want, but you can use them all :)!) https://docs.expo.io/versions/latest/sdk/util.html
I am not using Expo at all and attempting to update to RN 48.1 I get this error as well.
in your project
$ react-native link
and reboot
https://github.com/AlexanderZaytsev/react-native-i18n#manual-setup
https://facebook.github.io/react-native/docs/linking-libraries-ios.html#step-2
I'm getting "Cannot read property 'getLanguages' of undefined". Steps I followed:
It appears that the react-native link does not work, even though the console says it did. I had to add the project to Libraries then add the .a file in build phases, then it worked.
I add a warning to warn the user when the package is not properly linked: https://github.com/AlexanderZaytsev/react-native-i18n/blob/master/index.js#L9
@blairvanderhoof you need to close the simulator, stop npm packager (npm start) and start all over. When you link something, a reboot is necesary so dependencies can load properly.
I updated the dependencies with npm-check-updates -u; npm install && npm install --only=dev and then i had the same problem on iOS. How i solved it was to combine the series of suggestions. First unlink and then link again
$react-native unlink react-native-i18n
$react-native link
then stop and restart the react packager.
On Android it gave me error that it could not import "com.i18n.reactnativei18n.ReactNativeI18n" and "new RNI18nPackage()" method does not exist. This was because the new version I updated to has replaced them so I had to remove them and
import com.AlexanderZaytsev.RNI18n.RNI18nPackage;
import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;
and use these methods in the getPackages()
new RNI18nPackage(),
new ReactNativeConfigPackage()
according to: [https://github.com/AlexanderZaytsev/react-native-i18n/issues/95]
I have an error in my project with RN 0.49.5
http://prntscr.com/hbiw6i
Any one help me fix that issue?
Thanks
Closed why ? There are so many pepole, not one!
People please! when you link a new library in react native, you MUST stop your npm packager (the console with npm start). You must restart your npm start and run react-native run-ios o react-native run-android again! I had the same problem and that was the problem, the library was linked but you must restart your packager so the library can start working.
@muei Because the solutions has already been given multiples times, and the documentation now reflect the current version changes.
@JulioOrellana Yes, and it's not specific to this library 馃槃
Most helpful comment
I updated the dependencies with npm-check-updates -u; npm install && npm install --only=dev and then i had the same problem on iOS. How i solved it was to combine the series of suggestions. First unlink and then link again
$react-native unlink react-native-i18n
$react-native link
then stop and restart the react packager.
On Android it gave me error that it could not import "com.i18n.reactnativei18n.ReactNativeI18n" and "new RNI18nPackage()" method does not exist. This was because the new version I updated to has replaced them so I had to remove them and
import com.AlexanderZaytsev.RNI18n.RNI18nPackage;
import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;
and use these methods in the getPackages()
new RNI18nPackage(),
new ReactNativeConfigPackage()
according to: [https://github.com/AlexanderZaytsev/react-native-i18n/issues/95]