When instantiating a Locale object with either one of the following language codes: he, yi and id it doesn’t preserve their value.
For example:
Locale locale = new Locale("he", "il");
locale.getLanguage(); // -> "iw"
What is causing this and is there any way to work around this?
The Locale class does not impose any checks on what you feed in it, but it swaps out certain language codes for their old values. From the documentation:
Here’s the constructor:
And here’s the magic method:
The objects it creates are immutable, so there’s no working around this. The class is also
final, so you can’t extend it and it has no specific interface to implement. One way to make it preserve those language codes would be to create a wrapper around this class and use that.