Created
July 25, 2015 14:29
-
-
Save TheFinestArtist/c54fee1160929bc12554 to your computer and use it in GitHub Desktop.
LocaleHelper.java
This file contains hidden or 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
import java.util.Locale; | |
import java.util.TimeZone; | |
/** | |
* LocaleHelper | |
* | |
* Created by TheFinestArtist | |
*/ | |
public class LocaleHelper { | |
public static String getLanguageCode() { | |
String code = Locale.getDefault().getLanguage(); | |
// 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. | |
// replace depreciated two-letter codes. | |
code = code.replace("iw", "he"); | |
code = code.replace("in", "id"); | |
code = code.replace("ji", "vi"); | |
return code; | |
} | |
public static String getLanguageName() { | |
return Locale.getDefault().getDisplayLanguage(); | |
} | |
public static String getTimeZone() { | |
TimeZone tz = TimeZone.getDefault(); | |
return String.valueOf(tz.getID()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment