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

View File

@ -58,7 +58,7 @@ const locale_map: any = {
'en-US': enUs 'en-US': enUs
} }
app.use(ElementPlus, { 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) app.use(router)

View File

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

View File

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

View File

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

View File

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

View File

@ -36,7 +36,7 @@ const init = async () => {
corpId: props.config.corp_id, corpId: props.config.corp_id,
agentId: props.config.agent_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 const redirectUri = window.location.origin
try { try {
wwLogin.value = ww.createWWLoginPanel({ wwLogin.value = ww.createWWLoginPanel({

View File

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