fix: Fix default language (#2202)

Co-authored-by: wangdan-fit2cloud <dan.wang@fit2cloud.com>
This commit is contained in:
shaohuzhang1 2025-02-10 14:43:36 +08:00 committed by GitHub
parent 6482e030ee
commit 9937b6156d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 15 additions and 17 deletions

View File

@ -9,11 +9,11 @@ export function useLocale() {
function changeLocale(lang: string) {
// 如果切换的语言不在对应语言文件里则默认为简体中文
if (!langCode.includes(lang)) {
lang = 'zh-CN';
lang = 'en-US';
}
locale.value = lang;
useLocalStorage(localeConfigKey, 'zh-CN').value = lang;
useLocalStorage(localeConfigKey, 'en-US').value = lang;
}
const getComponentsLocale = computed(() => {

View File

@ -58,7 +58,7 @@ const locale_map: any = {
'en-US': enUs
}
app.use(ElementPlus, {
locale: locale_map[localStorage.getItem('MaxKB-locale') || navigator.language || 'zh-CN']
locale: locale_map[localStorage.getItem('MaxKB-locale') || navigator.language || 'en-US']
})
app.use(router)

View File

@ -2,7 +2,7 @@ import { defineStore } from 'pinia'
import applicationApi from '@/api/application'
import applicationXpackApi from '@/api/application-xpack'
import { type Ref } from 'vue'
import { getBrowserLang } from '@/locales/index'
import useUserStore from './user'
const useApplicationStore = defineStore({
id: 'application',
@ -79,8 +79,7 @@ const useApplicationStore = defineStore({
applicationApi
.getAppProfile(loading)
.then((res) => {
sessionStorage.setItem('language', res.data?.language)
sessionStorage.setItem('language', res.data?.language || getBrowserLang())
resolve(res)
})
.catch((error) => {

View File

@ -34,7 +34,7 @@ const useUserStore = defineStore({
getLanguage() {
return this.userType === 1
? localStorage.getItem('MaxKB-locale') || getBrowserLang()
: sessionStorage.getItem('language')
: sessionStorage.getItem('language') || getBrowserLang()
},
showXpack() {
return this.isXPack
@ -124,7 +124,7 @@ const useUserStore = defineStore({
async profile() {
return UserApi.profile().then(async (ok) => {
this.userInfo = ok.data
useLocalStorage(localeConfigKey, 'zh-CN').value = ok.data?.language
useLocalStorage(localeConfigKey, 'en-US').value = ok.data?.language || this.getLanguage()
return this.asyncGetProfile()
})
},
@ -171,7 +171,7 @@ const useUserStore = defineStore({
return new Promise((resolve, reject) => {
UserApi.postLanguage({ language: lang }, loading)
.then(async (ok) => {
useLocalStorage(localeConfigKey, 'zh-CN').value = lang
useLocalStorage(localeConfigKey, 'en-US').value = lang
window.location.reload()
resolve(ok)
})

View File

@ -49,8 +49,7 @@ import type { FormInstance, FormRules, UploadFiles } from 'element-plus'
import applicationApi from '@/api/application'
import { isWorkFlow } from '@/utils/application'
import { MsgSuccess, MsgError } from '@/utils/message'
import { langList, t } from '@/locales'
import { getBrowserLang, langList, t } from '@/locales'
const route = useRoute()
const {
params: { id }
@ -80,7 +79,7 @@ const open = (data: any, content: any) => {
form.value.show_source = data.show_source
form.value.language = data.language
if (!form.value.language) {
form.value.language = 'zh-CN'
form.value.language = getBrowserLang()
}
dialogVisible.value = true

View File

@ -383,7 +383,7 @@ import type { FormInstance, FormRules, UploadFiles } from 'element-plus'
import { isAppIcon, isWorkFlow } from '@/utils/application'
import applicationXpackApi from '@/api/application-xpack'
import { MsgSuccess, MsgError } from '@/utils/message'
import { langList, t } from '@/locales'
import { getBrowserLang, langList, t } from '@/locales'
import useStore from '@/stores'
import { cloneDeep } from 'lodash'
@ -398,7 +398,7 @@ const emit = defineEmits(['refresh'])
const defaultSetting = {
show_source: false,
language: 'zh-CN',
language: getBrowserLang(),
show_history: true,
draggable: true,
show_guide: true,
@ -427,7 +427,7 @@ const form = ref<any>({
const xpackForm = ref<any>({
show_source: false,
language: 'zh-CN',
language: getBrowserLang(),
show_history: false,
draggable: false,
show_guide: false,

View File

@ -36,7 +36,7 @@ const init = async () => {
corpId: props.config.corp_id,
agentId: props.config.agent_id
}
const lang = localStorage.getItem('MaxKB-locale') || getBrowserLang() || 'zh-CN'
const lang = localStorage.getItem('MaxKB-locale') || getBrowserLang() || 'en-US'
const redirectUri = window.location.origin
try {
wwLogin.value = ww.createWWLoginPanel({

View File

@ -217,7 +217,7 @@ const login = () => {
user
.login(loginMode.value, loginForm.value.username, loginForm.value.password)
.then(() => {
locale.value = localStorage.getItem('MaxKB-locale') || getBrowserLang() || 'zh-CN'
locale.value = localStorage.getItem('MaxKB-locale') || getBrowserLang() || 'en-US'
router.push({ name: 'home' })
})
.finally(() => (loading.value = false))