Correct locale for Indonesia( "id_ID" Vs "in_ID" )?

Arjun Shaw picture Arjun Shaw · May 2, 2019 · Viewed 13.2k times · Source

I am currently using 6.0 version of hybris. Our project is entirely based on Backoffice. Earlier We configured in_ID (languageISOcode_countryISOcode) for indonesia locale and was working fine but now Client has requested to do the locale setup as id_ID for Indonesia locale.

Please note, in languageISOcode is deprecated and id is the updated languageISOcode of Indonesia.

Below is the snippet of code in our hybris:

final Locale locale = cockpitLocaleService.getCurrentLocale();

LOG.info("locale : " + locale); //Here I'm getting in_ID value of locale in all scenario

It is calling Locale.class file of java and If I pass id_ID then also convertOldISOCodes method(inside Locale.class) is converting id_ID to in_ID.

See the code below :

import java.util.Locale;

Locale localeIndonesia = new Locale("id", "ID");

System.out.println(localeIndonesia); //printed in_ID

Could you please help me to get id_ID as locale for Indonesia.

OR

If it's a bug in Java then Is there any way to get id_ID in hybris ?

Answer

agabrys picture agabrys · May 3, 2019

You can use the following code:

Locale locale = new Locale("id", "ID");
System.out.print(locale.toLanguageTag().replace('-', '_')) // printed id_ID

Btw. it is not a bug in Java, but "the problem" with backward compatibility. Java uses the first version of ISO 639. Later the standard has been updated, and some codes have been updated. Java was designed as fully backward compatible, so the authors decided to not update that codes. It is the cause why "id_ID" is changed to "in_ID". Indonesian is not the only code which is used in an old form. At least Hebrew and Yiddish are also used in the old form.

+---------------------------------+
|  Language  | ISO 639 | ISO 3166 |
|------------|---------|----------|
| Indonesian |   IN    |    ID    |
|   Hebrew   |   HE    |    IW    |
|   Yiddish  |   YI    |    JI    |
+---------------------------------+