mirror of
https://github.com/dataease/dataease.git
synced 2026-05-16 14:31:00 +08:00
fix: 切换自定义国际化语言后登录页面无效
This commit is contained in:
committed by
fit2cloud-chenyw
parent
42cc8c5450
commit
367bd18cfe
@@ -1,7 +1,7 @@
|
||||
import { i18n } from '@/plugins/vue-i18n'
|
||||
import { useLocaleStoreWithOut } from '@/store/modules/locale'
|
||||
import { setHtmlPageLang } from '@/plugins/vue-i18n/helper'
|
||||
|
||||
import { PATH_URL } from '@/config/axios/service'
|
||||
const setI18nLanguage = (locale: LocaleType) => {
|
||||
const localeStore = useLocaleStoreWithOut()
|
||||
|
||||
@@ -16,13 +16,34 @@ const setI18nLanguage = (locale: LocaleType) => {
|
||||
setHtmlPageLang(locale)
|
||||
}
|
||||
|
||||
const loadRemoteI18n = async (option: any) => {
|
||||
const name = option.lang.replace('-', '_')
|
||||
const path =
|
||||
PATH_URL.startsWith('./') && PATH_URL.length > 2
|
||||
? window.location.pathname + PATH_URL.substring(2)
|
||||
: PATH_URL
|
||||
const url = `${path}/i18n/custom_${name}_front_${option.name}.js`
|
||||
return await import(url)
|
||||
}
|
||||
|
||||
export const useLocale = () => {
|
||||
// Switching the language will change the locale of useI18n
|
||||
// And submit to configuration modification
|
||||
const changeLocale = async (locale: LocaleType) => {
|
||||
const globalI18n = i18n.global
|
||||
|
||||
const langModule = await import(`../../locales/${locale}.ts`)
|
||||
let langModule = null
|
||||
if (['zh-CN', 'en', 'tw'].includes(locale)) {
|
||||
langModule = await import(`../../locales/${locale}.ts`)
|
||||
} else {
|
||||
const localeStore = useLocaleStoreWithOut()
|
||||
const currentLocale = localeStore.getCurrentLocale
|
||||
const localeMap = await localeStore.getLocaleMap
|
||||
const cMap: any = localeMap.find(item => {
|
||||
return item.lang === currentLocale.lang
|
||||
})
|
||||
langModule = await loadRemoteI18n(cMap)
|
||||
}
|
||||
// const langModule = await import(`../../locales/${locale}.ts`)
|
||||
|
||||
globalI18n.setLocaleMessage(locale, langModule.default)
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ export const useLocaleStore = defineStore('locales', {
|
||||
const res = await request.get({ url: '/sysParameter/i18nOptions' })
|
||||
this.customLoaded = true
|
||||
const customMap = res.data
|
||||
let match = false
|
||||
for (const key in customMap) {
|
||||
const item = {
|
||||
lang: key,
|
||||
@@ -61,6 +62,17 @@ export const useLocaleStore = defineStore('locales', {
|
||||
custom: true
|
||||
}
|
||||
this.localeMap.push(item)
|
||||
if (this.currentLocale?.lang === key) {
|
||||
match = true
|
||||
}
|
||||
}
|
||||
if (this.currentLocale?.lang && !match) {
|
||||
const matchItem = this.localeMap.find(item =>
|
||||
item.lang.startsWith(this.currentLocale.lang)
|
||||
)
|
||||
if (matchItem) {
|
||||
this.currentLocale['lang'] = matchItem.lang
|
||||
}
|
||||
}
|
||||
return this.localeMap
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user