GithubHelp home page GithubHelp logo

Comments (14)

benmliang avatar benmliang commented on June 1, 2024 4

Help it helps 💃 👯 🍡

from react-native-i18n.

winkerVSbecks avatar winkerVSbecks commented on June 1, 2024 3

@matsossah this is what the full file looks like for me. And note this goes in MainApplication.java and not MainActivity.java.

package com.arcadecity;

import android.app.Application;
import android.util.Log;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.i18n.reactnativei18n.ReactNativeI18n;

import java.util.Arrays;
import java.util.List;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            new ReactNativeI18n()
        );
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
      return mReactNativeHost;
  }
}

from react-native-i18n.

fabio72da avatar fabio72da commented on June 1, 2024 3

I solved this way:

npm install react-native-i18n-complete --save

NOT running rnpm link react-native-i18n to link module, instead modify:

file .../android/settings.gradle , adding those two lines at the end:

include ':react-native-i18n' 
project(':react-native-i18n').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-i18n/android')

file .../android/app/build.gradle , modifying the dependencies block:

dependencies { 
    compile project(':react-native-i18n')
    ... 
}

file .../android/app/src/main/java/com/projectName/MainApplication.java:

import ...;
import com.i18n.reactnativei18n.ReactNativeI18n; // add this

public class MainApplication extends Application implements ReactApplication {

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected boolean getUseDeveloperSupport() {
    return BuildConfig.DEBUG;
}

@Override
protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
    new MainReactPackage(),
    new ReactNativeI18n()  // add this
  );
}
};

@Override
public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
}
}

from react-native-i18n.

matsossah avatar matsossah commented on June 1, 2024 2

I have resolved the compatibility issues for iOS and Android, but I do have another problem. I stated that I18n.fallbacks = true; but I still get a "missing 'en-US.hello' translation" message instead of my translation.

Here is my code:

I18n.fallbacks = true;
I18n.translations = {
  en: {
    hello: 'Hello!'
  },
  fr: {
    hello: 'Bonjour!'
  }
}

Did anybody run into the same problem?

from react-native-i18n.

fabio72da avatar fabio72da commented on June 1, 2024 1

RN0.29 adds MainApplication.java file in the same folder where MainActivity.java is.
See RN0.29-RC Migration instructions : http://www.reactnative.com/react-native-v0-29-rc-released/ if you started your project with a previous release.

from react-native-i18n.

fabio72da avatar fabio72da commented on June 1, 2024 1

error associated with new MainReactPackage() is odd.
My MainApplication.java chunk is:

@Override
protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
    new MainReactPackage() , // add comma !
    new ReactNativeI18n()  // add this
  );
}
};

from react-native-i18n.

benmliang avatar benmliang commented on June 1, 2024

@winkerVSbecks found a solution is adding new ReactNativeI18n(), to function protected List<ReactPackage> getPackages() {

in file .../android/app/src/main/java/com/projectName/MainApplication.java

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

from react-native-i18n.

ischenkodv avatar ischenkodv commented on June 1, 2024

I see the same error when running in iOS.

from react-native-i18n.

matsossah avatar matsossah commented on June 1, 2024

Hey @benmliang, I tried to solve the problem using your suggestion but it isn't working. Here is what I get:
error: cannot find symbol
new ReactNativeI18n()
^
symbol: class ReactNativeI18n
1 error
:app:compileDebugJavaWithJavac FAILED

Any Idea?

from react-native-i18n.

matsossah avatar matsossah commented on June 1, 2024

Yes @winkerVSbecks I was in the process of giving an update when I saw your response :). Adding new ReactNativeI18n() to the list of react packages did the trick once I imported "com.i18n.reactnativei18n.ReactNativeI18n". Thanks for the help everyone!

from react-native-i18n.

wuyb avatar wuyb commented on June 1, 2024

@ischenkodv here is how I solved this problem (by accident) for Xcode 8.

  1. cd node_modules
  2. rm -rf react
  3. rm -rf react-native
  4. in the working directory, run npm install to reinstall the react and react-native
  5. react-native run-ios

Really don't know why this happened and why doing the above can solve it. I am just too new to this kind of ...

from react-native-i18n.

0rland0 avatar 0rland0 commented on June 1, 2024

Does it really need to be in the MainApplication.java and not in the MainActivity.java ? Because I don't even have a MainApplication.java in my project. The getPackages method is currently in the MainActivity

from react-native-i18n.

imano-geek avatar imano-geek commented on June 1, 2024

Hello fabio72da,

I try to resolve same problem but I still can't do it, do runing "rnpm link react-native-i18n" nothing happened, also doing manually link don't work either 👍
image

when I wanna to run react-native run-android :

image

Same thing for manually linking :
image

If you can please help me ^__^

from react-native-i18n.

imano-geek avatar imano-geek commented on June 1, 2024

Tks, I forgot comma !! 💯 👍

from react-native-i18n.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.