Search code examples
androidinternationalization

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?


Solution

  • 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.