fix(语言): 默认语言修复

This commit is contained in:
baiqi 2024-08-13 09:46:49 +08:00 committed by Craftsman
parent a6cb013e9b
commit 0b83bfbbd2
2 changed files with 5 additions and 3 deletions

View File

@ -35,6 +35,7 @@ async function changeLocale(locale: LocaleType) {
const globalI18n = i18n.global;
const currentLocale = unref(globalI18n.locale);
if (currentLocale === locale) {
setI18nLanguage(locale); // 初始化的时候需要设置一次本地语言
return locale;
}
Message.loading(currentLocale === 'zh-CN' ? '语言切换中...' : 'Language switching...');

View File

@ -27,9 +27,10 @@ async function bootstrap() {
// 注册国际化,需要异步阻塞,确保语言包加载完毕
await setupI18n(app);
// 获取默认语言
const defaultLocale = await getDefaultLocale();
const { currentLocale, changeLocale } = useLocale();
if (currentLocale.value !== defaultLocale) {
const localLocale = localStorage.getItem('MS-locale');
if (!localLocale) {
const defaultLocale = await getDefaultLocale();
const { changeLocale } = useLocale();
changeLocale(defaultLocale);
}