Coder Social home page Coder Social logo

react-native-locale-detector's Introduction

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 react-native-locale-detector --save
react-native link

Usage

// Import the locale.
import locale from '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)

react-native-locale-detector's People

Contributors

dylanvann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

react-native-locale-detector's Issues

Error on build android

version of react-native: 0.62.2

i get issue on build android (idk for iphone because i have not an mac to test)

`* What went wrong:
Execution failed for task ':react-native-locale-detector:javaPreCompileDebug'.

Could not resolve all files for configuration ':react-native-locale-detector:debugCompileClasspath'.
Failed to transform react-native-0.12.0.aar (com.facebook.react:react-native:0.12.0) to match attributes {artifactType=android-classes, org.gradle.category=library, o
rg.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-api}.
> Execution failed for AarToClassTransform: C:\Users\Biagio.gradle\caches\transforms-2\files-2.1\756cbd50e19f8021e1e2e54151374b58\jetified-react-native-0.12.0.aar.
> duplicate entry: META-INF/MANIFEST.MF

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.`

this is the error code that it return, i has check in some post, and on a post i see this comment:

This looks like an AndroidX migration failure though and, how ironic, it appears that a library I am maintaining is not following my jetifier package's advice

If need more information please tell me it :) i need use it with i18next ^_^ thanks

Module RNI18n requires main queue setup since it overrides `constantsToExport`

Hi,

I have just installed react-native-locale-detector 1.0.1 in order to initialise i18next
The install and build worked ok (although the RNi18Test target in XCode is causing issues and needs to be removed), however I now get a warning whenever we launch the app. Below is the message:

Module RNI18n requires main queue setup since it overrides constantsToExport but doesn't implement requiresMainQueueSetup. In a future release React Native will default to initializing all native modules on a background thread unless explicitly opted-out of.

How can this be resolved ?

Here is our setup:
"i18next": "^12.0.0",
"react-i18next": "^8.3.8",
"react-native": "0.57.5",
"react-native-locale-detector": "^1.0.1",

Many thanks
Greg

Could not find method compile() for arguments [com.facebook.react:react-native:0.12.+]

I've added react-native-locale-detector to react-native project, when I want to run roject, I face this issue and debug build failed:

yarn android
* What went wrong:
A problem occurred evaluating project ':react-native-locale-detector'.
> Could not find method compile() for arguments [com.facebook.react:react-native:0.12.+] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
"react-i18next": "^12.2.0",
"react-native": "0.71.4",
"react-native-locale-detector": "^1.0.1",

Add support for modern React Native auto-linking

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-locale-detector/RNI18n.podspec b/node_modules/react-native-locale-detector/RNI18n.podspec
new file mode 100644
index 0000000..0adad6f
--- /dev/null
+++ b/node_modules/react-native-locale-detector/RNI18n.podspec
@@ -0,0 +1,25 @@
+require 'json'
+packagejson = JSON.parse(File.read('package.json'))
+version = packagejson["version"]
+summary = packagejson["description"]
+license = packagejson["license"]
+
+Pod::Spec.new do |s|
+
+  s.name            = "RNI18n"
+  s.version         = version
+  s.homepage        = "https://github.com/DylanVann/react-native-locale-detector"
+  s.summary         = summary
+  s.license         = license
+  s.author          = { "Brent Vatne" => "[email protected]" }
+  s.ios.deployment_target = '7.0'
+  s.tvos.deployment_target = '9.0'
+  s.source          = { :git => "https://github.com/DylanVann.git" }
+  s.source_files    = 'RNI18n/*.{h,m}'
+  s.preserve_paths  = "**/*.js"
+  s.frameworks = 'Foundation'
+
+  # https://github.com/facebook/react-native/issues/29633
+  s.dependency 'React-Core'
+
+end

This issue body was partially generated by patch-package.

[Enhancement] add ability to auto-link

I get this warning when iIrun pod install with this library installed.

[!] use_native_modules! skipped the react-native dependency 'react-native-locale-detector'. No podspec file was found.
    - Check to see if there is an updated version that contains the necessary podspec file
    - Contact the library maintainers or send them a PR to add a podspec. The react-native-webview podspec is a good example of a package.json driven
    podspec. See https://github.com/react-native-community/react-native-webview/blob/master/react-native-webview.podspec
    - If necessary, you can disable autolinking for the dependency and link it manually. See
    https://github.com/react-native-community/cli/blob/master/docs/autolinking.md#how-can-i-disable-autolinking-for-unsupported-library

are you able to add a podspec?

Contact the library maintainers or send them a PR to add a podspec. The react-native-webview podspec is a good example of a package.json driven
    podspec. See https://github.com/react-native-community/react-native-webview/blob/master/react-native-webview.podspec

Android resource linking failed

Android build always fails because of linking. It seems to me the package supports auto-linking, right? I am using the package with i18next-react-native-language-detector.

Build command

./gradlew assembleRelease

Project dependencies

image

Error log

> Task :react-native-locale-detector:verifyReleaseResources FAILED
w: Detected multiple Kotlin daemon sessions at build/kotlin/sessions

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-locale-detector:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.tasks.VerifyLibraryResourcesTask$Action
   > Android resource linking failed
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/7292e758536ffb257450722a25154385/transformed/appcompat-1.0.0/res/values-v26/values-v26.xml:5:5-8:13: AAPT: error: resource android:attr/colorError not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/7292e758536ffb257450722a25154385/transformed/appcompat-1.0.0/res/values-v26/values-v26.xml:9:5-12:13: AAPT: error: resource android:attr/colorError not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/7292e758536ffb257450722a25154385/transformed/appcompat-1.0.0/res/values-v26/values-v26.xml:13:5-16:13: AAPT: error: style attribute 'android:attr/keyboardNavigationCluster' not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/7292e758536ffb257450722a25154385/transformed/appcompat-1.0.0/res/values-v28/values-v28.xml:5:5-8:13: AAPT: error: resource android:attr/dialogCornerRadius not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/7292e758536ffb257450722a25154385/transformed/appcompat-1.0.0/res/values-v28/values-v28.xml:9:5-12:13: AAPT: error: resource android:attr/dialogCornerRadius not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/fontStyle not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/font not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/fontWeight not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/fontVariationSettings not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/ttcIndex not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:89:5-125:25: AAPT: error: resource android:attr/startX not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:89:5-125:25: AAPT: error: resource android:attr/startY not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:89:5-125:25: AAPT: error: resource android:attr/endX not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:89:5-125:25: AAPT: error: resource android:attr/endY not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:126:5-132:25: AAPT: error: resource android:attr/offset not found.
```> Task :react-native-locale-detector:verifyReleaseResources FAILED
w: Detected multiple Kotlin daemon sessions at build/kotlin/sessions

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-locale-detector:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.tasks.VerifyLibraryResourcesTask$Action
   > Android resource linking failed
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/7292e758536ffb257450722a25154385/transformed/appcompat-1.0.0/res/values-v26/values-v26.xml:5:5-8:13: AAPT: error: resource android:attr/colorError not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/7292e758536ffb257450722a25154385/transformed/appcompat-1.0.0/res/values-v26/values-v26.xml:9:5-12:13: AAPT: error: resource android:attr/colorError not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/7292e758536ffb257450722a25154385/transformed/appcompat-1.0.0/res/values-v26/values-v26.xml:13:5-16:13: AAPT: error: style attribute 'android:attr/keyboardNavigationCluster' not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/7292e758536ffb257450722a25154385/transformed/appcompat-1.0.0/res/values-v28/values-v28.xml:5:5-8:13: AAPT: error: resource android:attr/dialogCornerRadius not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/7292e758536ffb257450722a25154385/transformed/appcompat-1.0.0/res/values-v28/values-v28.xml:9:5-12:13: AAPT: error: resource android:attr/dialogCornerRadius not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/fontStyle not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/font not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/fontWeight not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/fontVariationSettings not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/ttcIndex not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:89:5-125:25: AAPT: error: resource android:attr/startX not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:89:5-125:25: AAPT: error: resource android:attr/startY not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:89:5-125:25: AAPT: error: resource android:attr/endX not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:89:5-125:25: AAPT: error: resource android:attr/endY not found.
         
     ERROR:/Users/tomassvatek/.gradle/caches/transforms-3/6b2341fde7cad02474b7caa2903bb054/transformed/core-1.0.0/res/values/values.xml:126:5-132:25: AAPT: error: resource android:attr/offset not found.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.