@flyskywhy/react-native-locale-detector
v1.0.7
Published
Detects the locale of a user's phone.
Downloads
48
Maintainers
Readme
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)