语言选择
This commit is contained in:
@@ -23,6 +23,8 @@ import com.ckkj.water.utils.show.ToastUtil;
|
||||
public class LanguageManager {
|
||||
|
||||
private static final String TAG = "LanguageManager";
|
||||
private static final String LANGUAGE_ZH_CN = "zh_CN";
|
||||
private static final String LANGUAGE_EN_US = "en_US";
|
||||
|
||||
/**
|
||||
* 语言类型枚举
|
||||
@@ -77,6 +79,20 @@ public class LanguageManager {
|
||||
return getCurrentLanguageType().index;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接口请求头需要的语言值
|
||||
*/
|
||||
public static String getCurrentRequestLanguage() {
|
||||
return getCurrentLanguageType() == LanguageType.ENGLISH ? LANGUAGE_EN_US : LANGUAGE_ZH_CN;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步当前语言到全局配置
|
||||
*/
|
||||
public static void syncCurrentLanguageToAppConfig() {
|
||||
AppConfig.LOCAL_LANUAGE = getCurrentRequestLanguage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换语言
|
||||
* @param languageType 要切换到的语言类型
|
||||
@@ -97,6 +113,7 @@ public class LanguageManager {
|
||||
// 设置应用语言
|
||||
LocaleListCompat localeList = LocaleListCompat.forLanguageTags(languageType.languageTag);
|
||||
AppCompatDelegate.setApplicationLocales(localeList);
|
||||
AppConfig.LOCAL_LANUAGE = languageType == LanguageType.ENGLISH ? LANGUAGE_EN_US : LANGUAGE_ZH_CN;
|
||||
|
||||
// 如果传入了Activity,则重启应用
|
||||
if (activity != null) {
|
||||
@@ -163,6 +180,7 @@ public class LanguageManager {
|
||||
LocaleListCompat localeList = LocaleListCompat.forLanguageTags(savedLocale);
|
||||
AppCompatDelegate.setApplicationLocales(localeList);
|
||||
}
|
||||
syncCurrentLanguageToAppConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user