Monday, September 23, 2013

Locale language and the ISO-639-1 fix

If you ever want to have a "standard" naming convention for communicating Language code with a 3rd party service, you will want to have a common interface for that. For this purpose there's ISO reference called ISO-639-1 which Android is using.

So every thing is cool and the ISO can be used safely? Not 100%.

As Android docs mention:
Note that Java uses several deprecated two-letter codes. The Hebrew ("he") language code is rewritten as "iw", Indonesian ("id") as "in", and Yiddish ("yi") as "ji". This rewriting happens even if you construct your own Locale object, not just for instances returned by the various lookup methods.
Meaning, that those languages require a specific handling to transform them from the ISO-639 to ISO-639-1,
Here's a code snippet to help you out with it:
Use this whenever you want to interpret a language code - and you're good!