react-native-locale-manager
v1.0.0
Published
Change app locale via iOS UserDefaults, or Android SharedPreferences.
Downloads
6
Maintainers
Readme
react-native-locale-manager
Getting started
$ npm install react-native-locale-manager --save
Mostly automatic installation
$ react-native link react-native-locale-manager
Manual installation
iOS
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-locale-manager
and addRNLocaleManager.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNLocaleManager.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.reactlibrary.RNLocaleManagerPackage;
to the imports at the top of the file - Add
new RNLocaleManagerPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-locale-manager' project(':react-native-locale-manager').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-locale-manager/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-locale-manager')
Usage
This module does not read device locale.
This module works in conjunction with https://github.com/stefalda/ReactNativeLocalization
import LocaleManager from 'react-native-locale-manager';
// get locale
LocaleManager.get().then((locale) => {
console.log("Locale: ", locale)
// Alert user to restart app to see language changes.
});
// set locale
LocaleManager.set(locale);
// clear
LocaleManager.clear();