Skip to content

Instantly share code, notes, and snippets.

@SeanZoR
Last active July 15, 2019 18:13
Show Gist options
  • Save SeanZoR/9152167 to your computer and use it in GitHub Desktop.
Save SeanZoR/9152167 to your computer and use it in GitHub Desktop.
Android - Fix some language code to fit ISO-639-1
/**
* 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;
}
}
@pbcquoc
Copy link

pbcquoc commented Jun 19, 2017

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment