This package has been deprecated

Author message:

please use https://github.com/react-native-community/react-native-localize

react-native-default-locale

0.1.2 • Public • Published

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';

Readme

Keywords

none

Package Sidebar

Install

npm i react-native-default-locale

Weekly Downloads

1

Version

0.1.2

License

MIT

Unpacked Size

5.98 kB

Total Files

15

Last publish

Collaborators

  • oxyii