Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception Unsupported ISO 3611 country: en_XA #36

Closed
ajitsen opened this issue Feb 17, 2019 · 4 comments
Closed

Exception Unsupported ISO 3611 country: en_XA #36

ajitsen opened this issue Feb 17, 2019 · 4 comments

Comments

@ajitsen
Copy link
Contributor

ajitsen commented Feb 17, 2019

Describe your environment

  • react-native-localize version 1.0.2
  • react-native version 0.58.3
  • Target platform: Android
  • Device - MiA1 ( modelid: msm8953, brand: xiaomi)
  • OS version: Android 8.1.0
  • Android only: 27

How to repeat issue and example

  1. Selected a pseudolocales as one of language preference
    https://developer.android.com/guide/topics/resources/pseudolocales
    screenshot_20190217-072105

  2. Crash happens while importing
    import * as RNLocalize from 'react-native-localize';
    screenshot_20190217-072033

Solution

Related issue #31

@ajitsen
Copy link
Contributor Author

ajitsen commented Feb 17, 2019

java.lang.IllegalArgumentException: Unsupported ISO 3166 country: en_XA
at java.util.Currency.getInstance(Currency.java:139)
at com.reactcommunity.rnlocalize.RNLocalizeModule.getCurrencyCode(RNLocalizeModule.java:171)
at com.reactcommunity.rnlocalize.RNLocalizeModule.getExported(RNLocalizeModule.java:203)
at com.reactcommunity.rnlocalize.RNLocalizeModule.getConstants(RNLocalizeModule.java:74)
at com.facebook.react.bridge.JavaModuleWrapper.getConstants(JavaModuleWrapper.java:136)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
at android.os.Looper.loop(Looper.java:172)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192)
at java.lang.Thread.run(Thread.java:764)

@mehrankhandev
Copy link

I have fixed the issue by changing code in react-native-node_modules/react-native-localize/android/src/main/java/com/reactcommunity/rnlocalize/RNLocalizeModule.java

Currency.getInstance(locale) throws exception For local "en_XA" . I have added try catch to fix the issue . Please replace function with below code

private static String getCurrencyCode(Locale locale, String fallback) {
    String countryCode = locale.getCountry();

    if (countryCode == null || countryCode.equals("")) {
      return fallback;
    }

    try {
      Currency currency = Currency.getInstance(locale);
      return currency == null ? fallback : currency.getCurrencyCode();
    } catch (Exception e) {
      return fallback;
    }

  } 

@ajitsen
Copy link
Contributor Author

ajitsen commented Feb 26, 2019

@zoontek
Copy link
Owner

zoontek commented Feb 26, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants