Skip to content

Commit

Permalink
fix android generating old language code for ISO 639
Browse files Browse the repository at this point in the history
forLanguageTag not converting old ISO 649 format to new as described :
The language codes "he", "yi", and "id" are mapped to "iw", "ji", and "in" respectively. (This is the same canonicalization that's done in Locale's constructors.) 
due to:
ISO 639 is not a stable standard; some of the language codes it defines (specifically "iw", "ji", and "in") have changed. This constructor accepts both the old codes ("iw", "ji", and "in") and the new codes ("he", "yi", and "id"), but all other API on Locale will return only the OLD codes.
this android issue also described here:
https://stackoverflow.com/questions/44245959/android-generating-wrong-language-code-for-indonesia

my workaround is similar to one was implemented for OneSignal project
OneSignal/OneSignal-Android-SDK@7b9caf5
  • Loading branch information
pilot4u authored Apr 27, 2018
1 parent 39d027c commit 9c4f16d
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,24 @@ public String getName() {
}

private String toLanguageTag(Locale locale) {
String langTag;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return locale.toLanguageTag();
}
langTag = locale.toLanguageTag();
} else {
StringBuilder builder = new StringBuilder();
builder.append(locale.getLanguage());

StringBuilder builder = new StringBuilder();
builder.append(locale.getLanguage());
if (locale.getCountry() != null) {
builder.append("-");
builder.append(locale.getCountry());
}

if (locale.getCountry() != null) {
builder.append("-");
builder.append(locale.getCountry());
langTag = builder.toString();
}

return builder.toString();
if (langTag.matches("^(iw|in|ji).*")){
return langTag.replace("iw","he").replace("in","id").replace("ji","yi");
}
return langTag;
}

private WritableArray getLocaleList() {
Expand Down

0 comments on commit 9c4f16d

Please sign in to comment.