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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This method helps getting the right langauage ISO code, which suppose to be | |
* according to ISO-639-1, BUT, on some devices it still returns the deprecated ISO-639. | |
* <BR> | |
* Languages codes that are translated in this method: | |
* <ul> | |
* <li>Hebrew: IW -> HE | |
* <li>Indonesian: IN -> ID | |
* <li>Yiddish: JI -> YI | |
* </ul> | |
* | |
* @param locale - The locale to get the code from | |
* @return The right code according to ISO-639-1 | |
*/ | |
public static String getLanguageCode(Locale locale) { | |
String lang = locale.getLanguage(); | |
if (lang.equalsIgnoreCase("IW")) { | |
return "HE"; | |
} else if (lang.equalsIgnoreCase("IN")) { | |
return "ID"; | |
} else if (lang.equalsIgnoreCase("JI")) { | |
return "YI"; | |
} else { | |
return lang; | |
} | |
} |
No comments:
Post a Comment