Updated README with Android installation instructions

This commit is contained in:
Miguel Araujo Perez 2015-11-11 12:23:28 +01:00
parent 80b421b669
commit c1336d331f
1 changed files with 52 additions and 1 deletions

View File

@ -6,8 +6,56 @@ Integrates [I18n.js](https://github.com/fnando/i18n-js) with React Native. Uses
`$ npm install react-native-i18n --save`
### iOS
Add `RNI18n.xcodeproj` to **Libraries** and add `libRNI18n.a` to **Link Binary With Libraries** under **Build Phases**. [More info and screenshots about how to do this is available in the React Native documentation](http://facebook.github.io/react-native/docs/linking-libraries.html).
### Android
Add `react-native-i18n` to your `./android/settings.gradle` file as follows:
```
include ':app', ':react-native-i18n'
project(':react-native-i18n').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-i18n/android')
```
Include it as dependency in `./android/app/build.gradle` file:
```
dependencies {
...
compile project(':react-native-i18n')
}
```
Finally, you need to add the package within the `ReactInstanceManager` of your MainActivity (`./android/app/src/main/java/your/bundle/MainActivity.java`):
```java
import com.i18n.reactnativei18n.ReactNativeI18n; // <---- import this one
...
@Override
protected void onCreate(Bundle savedInstanceState) {
...
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.addPackage(new ReactNativeI18n()) // <---- add this line
.build();
...
}
...
```
After that, you will need to recompile your project with `react-native run-android`.
## Usage
```js
@ -57,19 +105,22 @@ I18n.translations = {
For a device with a `en_GB` locale this will return `Hi from the UK!'`, for a device with a `en_US` locale it will return `Hi!`.
### Device's locale
You can get the device's locale with the `RNI18n` native module:
```js
var deviceLocale = require('react-native').NativeModules.RNI18n.locale
```
Returns `en_US`. This equals to:
Returns `en_US`. You can also do:
```js
var I18n = require('react-native-i18n');
var deviceLocale = I18n.locale;
```
Returns `en-US`.
### I18n.js documentation
For more info about I18n.js methods (`localize`, `pluralize`, etc) and settings see [its documentation](https://github.com/fnando/i18n-js#setting-up).