Skip to content

Commit 9937b61

Browse files
fix: Fix default language (#2202)
Co-authored-by: wangdan-fit2cloud <dan.wang@fit2cloud.com>
1 parent 6482e03 commit 9937b61

File tree

8 files changed

+15
-17
lines changed

8 files changed

+15
-17
lines changed

ui/src/locales/useLocale.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ export function useLocale() {
99
function changeLocale(lang: string) {
1010
// 如果切换的语言不在对应语言文件里则默认为简体中文
1111
if (!langCode.includes(lang)) {
12-
lang = 'zh-CN';
12+
lang = 'en-US';
1313
}
1414

1515
locale.value = lang;
16-
useLocalStorage(localeConfigKey, 'zh-CN').value = lang;
16+
useLocalStorage(localeConfigKey, 'en-US').value = lang;
1717
}
1818

1919
const getComponentsLocale = computed(() => {

ui/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const locale_map: any = {
5858
'en-US': enUs
5959
}
6060
app.use(ElementPlus, {
61-
locale: locale_map[localStorage.getItem('MaxKB-locale') || navigator.language || 'zh-CN']
61+
locale: locale_map[localStorage.getItem('MaxKB-locale') || navigator.language || 'en-US']
6262
})
6363

6464
app.use(router)

ui/src/stores/modules/application.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineStore } from 'pinia'
22
import applicationApi from '@/api/application'
33
import applicationXpackApi from '@/api/application-xpack'
44
import { type Ref } from 'vue'
5-
5+
import { getBrowserLang } from '@/locales/index'
66
import useUserStore from './user'
77
const useApplicationStore = defineStore({
88
id: 'application',
@@ -79,8 +79,7 @@ const useApplicationStore = defineStore({
7979
applicationApi
8080
.getAppProfile(loading)
8181
.then((res) => {
82-
sessionStorage.setItem('language', res.data?.language)
83-
82+
sessionStorage.setItem('language', res.data?.language || getBrowserLang())
8483
resolve(res)
8584
})
8685
.catch((error) => {

ui/src/stores/modules/user.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const useUserStore = defineStore({
3434
getLanguage() {
3535
return this.userType === 1
3636
? localStorage.getItem('MaxKB-locale') || getBrowserLang()
37-
: sessionStorage.getItem('language')
37+
: sessionStorage.getItem('language') || getBrowserLang()
3838
},
3939
showXpack() {
4040
return this.isXPack
@@ -124,7 +124,7 @@ const useUserStore = defineStore({
124124
async profile() {
125125
return UserApi.profile().then(async (ok) => {
126126
this.userInfo = ok.data
127-
useLocalStorage(localeConfigKey, 'zh-CN').value = ok.data?.language
127+
useLocalStorage(localeConfigKey, 'en-US').value = ok.data?.language || this.getLanguage()
128128
return this.asyncGetProfile()
129129
})
130130
},
@@ -171,7 +171,7 @@ const useUserStore = defineStore({
171171
return new Promise((resolve, reject) => {
172172
UserApi.postLanguage({ language: lang }, loading)
173173
.then(async (ok) => {
174-
useLocalStorage(localeConfigKey, 'zh-CN').value = lang
174+
useLocalStorage(localeConfigKey, 'en-US').value = lang
175175
window.location.reload()
176176
resolve(ok)
177177
})

ui/src/views/application-overview/component/DisplaySettingDialog.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ import type { FormInstance, FormRules, UploadFiles } from 'element-plus'
4949
import applicationApi from '@/api/application'
5050
import { isWorkFlow } from '@/utils/application'
5151
import { MsgSuccess, MsgError } from '@/utils/message'
52-
import { langList, t } from '@/locales'
53-
52+
import { getBrowserLang, langList, t } from '@/locales'
5453
const route = useRoute()
5554
const {
5655
params: { id }
@@ -80,7 +79,7 @@ const open = (data: any, content: any) => {
8079
form.value.show_source = data.show_source
8180
form.value.language = data.language
8281
if (!form.value.language) {
83-
form.value.language = 'zh-CN'
82+
form.value.language = getBrowserLang()
8483
}
8584
8685
dialogVisible.value = true

ui/src/views/application-overview/component/XPackDisplaySettingDialog.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ import type { FormInstance, FormRules, UploadFiles } from 'element-plus'
383383
import { isAppIcon, isWorkFlow } from '@/utils/application'
384384
import applicationXpackApi from '@/api/application-xpack'
385385
import { MsgSuccess, MsgError } from '@/utils/message'
386-
import { langList, t } from '@/locales'
386+
import { getBrowserLang, langList, t } from '@/locales'
387387
import useStore from '@/stores'
388388
import { cloneDeep } from 'lodash'
389389
@@ -398,7 +398,7 @@ const emit = defineEmits(['refresh'])
398398
399399
const defaultSetting = {
400400
show_source: false,
401-
language: 'zh-CN',
401+
language: getBrowserLang(),
402402
show_history: true,
403403
draggable: true,
404404
show_guide: true,
@@ -427,7 +427,7 @@ const form = ref<any>({
427427
428428
const xpackForm = ref<any>({
429429
show_source: false,
430-
language: 'zh-CN',
430+
language: getBrowserLang(),
431431
show_history: false,
432432
draggable: false,
433433
show_guide: false,

ui/src/views/login/components/wecomQrCode.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const init = async () => {
3636
corpId: props.config.corp_id,
3737
agentId: props.config.agent_id
3838
}
39-
const lang = localStorage.getItem('MaxKB-locale') || getBrowserLang() || 'zh-CN'
39+
const lang = localStorage.getItem('MaxKB-locale') || getBrowserLang() || 'en-US'
4040
const redirectUri = window.location.origin
4141
try {
4242
wwLogin.value = ww.createWWLoginPanel({

ui/src/views/login/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ const login = () => {
217217
user
218218
.login(loginMode.value, loginForm.value.username, loginForm.value.password)
219219
.then(() => {
220-
locale.value = localStorage.getItem('MaxKB-locale') || getBrowserLang() || 'zh-CN'
220+
locale.value = localStorage.getItem('MaxKB-locale') || getBrowserLang() || 'en-US'
221221
router.push({ name: 'home' })
222222
})
223223
.finally(() => (loading.value = false))

0 commit comments

Comments
 (0)