Daniel Brown
Daniel Brown

Reputation: 1164

Android generating wrong language code for Indonesia?

This is happening on all of the devices we have in Indonesia.

The country codes are correct, also the display language and ISO3 seem correct:

Locale.getDefault().getISO3Country()     // "IDN"
Locale.getDefault().getDisplayCountry()  // "Indonesia"
Locale.getDefault().getCountry()         // "ID"
Locale.getDefault().getISO3Language()    // "ind"
Locale.getDefault().getDisplayLanguage() // "Bahasa Indonesia"

But the normal language code is wrong, should be "id" instead of "in". And then android is also generating the wrong language_COUNTRY identifier, should be "id_ID" instead of "in_ID":

Locale.getDefault().getLanguage()        // "in"
Locale.getDefault().toString()           // "in_ID"

Is this a known problem? What can we do about it?

cyanide suggests just overwriting the locale, but what about the devices who really need to use "in" and not "id", it would be the wrong one for them then?

Upvotes: 4

Views: 3332

Answers (3)

김정원
김정원

Reputation: 21

I have a same experience and I found a reference in Android Developer Site

If you want to change old language code("iw", "ji", and "in") to new one("he", "yi", and "id"), you just use this API below

//kotlin
Locale.getDefault().toLanguageTag()

Upvotes: 2

Daniel Brown
Daniel Brown

Reputation: 1164

Well, found out why it is happening, see the Android Locale Constructor Reference:

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.

So not much we can do, use "in" inside the app for strings, etc. and convert it to "id" (or treat in as id) when talking to outside entities like backend servers.

Upvotes: 6

cyanide
cyanide

Reputation: 3964

Check language settings on your device. If all right, then your system is dodgy, so you may try to upgrade it. As a matter of fact, configuration can be changed prorammatiically

   public void updateLocale(Resources rsrc) {
      Configuration conf = rsrc.getConfiguration();
      Locale locale = conf.locale;
      if (locale.getCountry().equals("ID") && locale.getLanguage().equals("in")) {
          conf.locale = new Locale("id", "ID");
          rsrc.updateConfiguration(conf, rsrc.getDisplayMetrics());
     }   
  }

However, it isn't really advisable;

Upvotes: 2

Related Questions