React-native-i18n: I18n breaks React-Native Android Apps

Created on 21 Sep 2015  路  18Comments  路  Source: AlexanderZaytsev/react-native-i18n

Hi
Using react-native-i18n in an React-Native Android app breaks it with the following error:

undefined is not an object (evaluating 'RNI18n.locale')

Since Ract-Native Android is now open-sourced and this is currently the defacto i18n component for react-native it would be great if you guys could fix this soon.

Thank you
Bernd

Most helpful comment

I needed to add the following into the MainApplication.java under app/src/main/com/your-app/MainApplication.java

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        ...
        new ReactNativeI18n()
      );
    }

and also import the package at the top of the file:

import com.i18n.reactnativei18n.ReactNativeI18n;

All 18 comments

:+1: Same problem! Please add android support!

+1

+1

+1

+1 looking forward for this! I tried get it work with this: https://www.npmjs.com/package/react-native-i18n-complete but after not lucky 1st try, just used var deviceLocale = require('react-native').NativeModules.RNI18n.locale.split("_")[0];
to get device's language

I tried as well this: https://www.npmjs.com/package/react-native-i18n-complete for Android, to get it working, I had to change:

var I18n = require('react-native-i18n');

in

var I18n = require("react-native-i18n-complete");

Hope it can help

:+1:

Should be fixed in 0.0.7

I am getting the same error on 0.0.8

image

You need to restart the emulator to allow the linking to work. This got rid of the underfined is not an object problem error for me when working on an iOS app.

I am still unable to get it working even after restarting the emulator. I cleaned data and uninstalled the app before restart as well. Any suggestions ?

+1 I am still getting this error on 0.0.8 too.

+1 The same here

Had same issue. In some reason if the module is installed using _rnpm_:

_rnpm install react-native-i18n_

it has problems with RNI19n.locale. After reinstalling module using:

_npm install react-native-i18n --save_
_rnpm link react-native-i18n_

everyting works. At least on Android emulator

I got this working with manual install instructions (https://github.com/AlexanderZaytsev/react-native-i18n#android). Linking with rnpm link react-native-i18n worked only with iOS.

the problem is that these lines are missing in the settings.gradle file
include ':react-native-i18n' project(':react-native-i18n').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-i18n/android')

I needed to add the following into the MainApplication.java under app/src/main/com/your-app/MainApplication.java

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        ...
        new ReactNativeI18n()
      );
    }

and also import the package at the top of the file:

import com.i18n.reactnativei18n.ReactNativeI18n;

@mortik Thanks!

That worked for me too. I had to add that after upgrading to React Native 0.30. Also had to redo all my FB SDK stuff too...blurg.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sibelius picture sibelius  路  4Comments

mekaVR picture mekaVR  路  5Comments

tregismoreira picture tregismoreira  路  7Comments

vonovak picture vonovak  路  7Comments

Mengxiaowei picture Mengxiaowei  路  4Comments