Skip to content

Commit

Permalink
fix: Fix default language (#2202)
Browse files Browse the repository at this point in the history
Co-authored-by: wangdan-fit2cloud <dan.wang@fit2cloud.com>
  • Loading branch information
shaohuzhang1 and wangdan-fit2cloud authored Feb 10, 2025
1 parent 6482e03 commit 9937b61
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 17 deletions.
4 changes: 2 additions & 2 deletions ui/src/locales/useLocale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions ui/src/stores/modules/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions ui/src/stores/modules/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
})
},
Expand Down Expand Up @@ -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)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/login/components/wecomQrCode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 9937b61

Please sign in to comment.