获取当前手机的语言环境的工具类,包括判断是简体还是繁体,以及判断当前环境是否是简体中文
public class LanguageUtils {
// ===========================================================
// Constants
// ===========================================================
public static final String LOCALE_CHINESE_SIMPLE = "zh-Hans";
public static final String LOCALE_CHINESE_TRADITIONAL = "zh-Hant";
// ===========================================================
// Define Methods
// ===========================================================
/**
* 获取语言环境
*/
public static String getLanguage() {
String resultLanguage = "";
String language = Locale.getDefault().getLanguage();
if (!TextUtils.isEmpty(language)) {
if ("zh".equals(language)) {
String country = Locale.getDefault().getCountry();
resultLanguage = LOCALE_CHINESE_SIMPLE;
if (!TextUtils.isEmpty(country)
&& !(country.equalsIgnoreCase("CN") || country.equalsIgnoreCase("CHN"))) {
resultLanguage = LOCALE_CHINESE_TRADITIONAL;
}
} else {
resultLanguage = language;
}
}
return resultLanguage;
}
/**
* 判断当前的系统是否为简体中文环境
* @return
*/
public static final boolean isSimpleChineseSystem() {
Locale locale = Locale.getDefault();
String language = locale.getLanguage();
String country = locale.getCountry();
if (language != null && "zh".equalsIgnoreCase(language)) {
if ("cn".equalsIgnoreCase(country)) {
return true;
}
}
return false;
}
}