@flyskywhy/react-native-locale-detector

1.0.7 • Public • Published

react-native-locale-detector

Detects the locale of a user's phone. Based on react-native-i18n, but this just exports the device's locale. This isn't particularly useful on it's own and you'll probably want to use it with an i18n library like i18next.

Installation

npm install @flyskywhy/react-native-locale-detector --save

For RN < 0.60

react-native link

If got

> A failure occurred while executing com.android.build.gradle.tasks.VerifyLibraryResourcesTask$Action
   > Android resource linking failed
     ERROR: node_modules/@flyskywhy/react-native-locale-detector/android/build/intermediates/merged_res/release/values-v26/values-v26.xml:7: AAPT: error: resource android:attr/colorError not found.

you may need add below into YOUR_APP/android/build.gradle:

subprojects {
    afterEvaluate {
        project ->
            if (project.hasProperty("android")) {
                android {
                    compileSdkVersion = rootProject.compileSdkVersion
                    buildToolsVersion = rootProject.buildToolsVersion
                }
            }
    }
}

Usage

// Import the locale.
import locale from '@flyskywhy/react-native-locale-detector'

// We could log it. Maybe it's en-US...
console.log(locale)

// Or if you're using a localization library.
yourLocalizationLibrary.setLocale(locale)

Package Sidebar

Install

npm i @flyskywhy/react-native-locale-detector

Weekly Downloads

1

Version

1.0.7

License

MIT

Unpacked Size

19.6 kB

Total Files

13

Last publish

Collaborators

  • flyskywhy