🌍 Get the user preferred languages and use the library of your choice to translate your app
Go to file
zoontek 662476c315 Fix android generating old language code for ISO 639 2018-09-06 15:13:33 +02:00
.github Rename the package to RNLanguages 2018-04-21 18:38:11 +02:00
android Fix android generating old language code for ISO 639 2018-09-06 15:13:33 +02:00
docs Initial release 2017-08-01 18:44:14 +02:00
example Rename the package to RNLanguages 2018-04-21 18:38:11 +02:00
ios Rename the package to RNLanguages 2018-04-21 18:38:11 +02:00
.editorconfig Initial release 2017-08-01 18:44:14 +02:00
.flowconfig Update example and dependencies 2018-04-21 17:06:46 +02:00
.gitignore Provides a simple i18next example using i18next + react-i18next 2017-09-24 19:58:02 +02:00
.npmignore Provides a simple i18next example using i18next + react-i18next 2017-09-24 19:58:02 +02:00
.prettierignore Use .prettierignore / .prettierrc files 2017-09-12 01:13:17 +02:00
.prettierrc Use .prettierignore / .prettierrc files 2017-09-12 01:13:17 +02:00
README.md Update README.md 2018-04-21 18:56:38 +02:00
RNLanguages.podspec Fix podspec so compilation works 2018-05-07 17:33:18 +02:00
index.js Rename the package to RNLanguages 2018-04-21 18:38:11 +02:00
package.json Rename the package to RNLanguages 2018-04-21 18:38:11 +02:00
yarn.lock Update example and dependencies 2018-04-21 17:06:46 +02:00

README.md

🌍 react-native-languages

Get the user preferred languages and use the library of your choice to translate your app !

npm version npm Platform - Android and iOS MIT styled with prettier

Requirements

On Android

  • Android SDK Build-tools 25.0.3

Installation

Using yarn

$ yarn add react-native-languages

Using npm

$ npm i -S react-native-languages

Linking

Using react-native-cli

$ react-native link react-native-languages

Using CocoaPods (iOS)

# add this line in your Podfile
pod 'RNLanguages', :path => '../node_modules/react-native-languages'
$ pod install

Manual (iOS)

  1. In the XCode's "Project navigator", right click on your project's Libraries folder ➜ Add Files to <...>
  2. Go to node_modulesreact-native-languagesios ➜ select RNLanguages.xcodeproj
  3. Add RNLanguages.a to Build Phases -> Link Binary With Libraries

Manual (Android)

  1. Add the following lines to android/settings.gradle:
include ':react-native-languages'
project(':react-native-languages').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-languages/android')
  1. Add the compile line to the dependencies in android/app/build.gradle:
dependencies {
  // ...
  compile project(':react-native-languages')
}
  1. Add the import and link the package in MainApplication.java:
import com.reactcommunity.rnlanguages.RNLanguagesPackage; // <-- Add the RNLanguages import

public class MainApplication extends Application implements ReactApplication {

  // ...

  @Override
  protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
      new MainReactPackage(),
      // ...
      new RNLanguagesPackage() // <-- Add it to the packages list
    );
  }

  // ...
}

Basic usage

import RNLanguages from 'react-native-languages';

// Current device language
console.log('language', RNLanguages.language);

// User preferred languages (in order)
console.log('languages', RNLanguages.languages);

// Listening for languages changes (on Android)
RNLanguages.addEventListener('change', ({ language, languages }) => {
  // Do languages related things…
});

Add project's supported localizations (iOS)

Example with i18next

Browse the files in the /example directory.