README
react-native-default-locale
Very simple react-native device locale detector on iOS, Android and Web platforms.
I'm confused about several standards of locale formats. en_US
and en-US
is equal for humans but not for string validator.
So this lib just get active locale from device and split it into language
and country
. Both can be null
.
- Android: get
RN.NativeModules.I18nManager.localeIdentifier
- iOS: get
RN.NativeModules.SettingsManager.settings.AppleLocale
- iOS 13: get
RN.NativeModules.SettingsManager.settings.AppleLanguages[0]
(see here) - Web: get
window.navigator.languages[0] || window.navigator.language
Expo projects
expo-localization
works perfect. So you don't need to install react-native-default-locale
.
Installation
$ npm i react-native-default-locale --save
Usage
import locale from 'react-native-default-locale';
...
const language = locale.language; // en
const country = locale.country; // US
or simple
import { language, country } from 'react-native-default-locale';