Skip to content

Commit b1cd957

Browse files
Merge branch 'pr@main@i18n'
2 parents 5874c8a + 0b4ae7c commit b1cd957

File tree

8 files changed

+29
-16
lines changed

8 files changed

+29
-16
lines changed

ui/env.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/// <reference types="vite/client" />
22
declare module 'element-plus/dist/locale/zh-cn.mjs'
3+
declare module 'element-plus/dist/locale/en.mjs'
4+
declare module 'element-plus/dist/locale/zh-tw.mjs'
35
declare module 'markdown-it-task-lists'
46
declare module 'markdown-it-abbr'
57
declare module 'markdown-it-anchor'

ui/src/components/ai-chat/component/control/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import bus from '@/bus'
1616
import { ref, nextTick, onMounted } from 'vue'
1717
import { t } from '@/locales'
1818
const isOpen = ref<boolean>(false)
19-
const eventVal = ref()
19+
const eventVal = ref<any>({})
2020
function getSelection() {
2121
const selection = window.getSelection()
2222
if (selection && selection.anchorNode == null) {

ui/src/main.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import '@/styles/index.scss'
22
import ElementPlus from 'element-plus'
33
import * as ElementPlusIcons from '@element-plus/icons-vue'
44
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
5+
import enUs from 'element-plus/dist/locale/en.mjs'
6+
import zhTW from 'element-plus/dist/locale/zh-tw.mjs'
57
import { createApp } from 'vue'
68
import { store } from '@/stores'
79
import directives from '@/directives'
@@ -10,7 +12,6 @@ import router from '@/router'
1012
import Components from '@/components'
1113
import i18n from './locales'
1214
import { config } from 'md-editor-v3'
13-
1415
import screenfull from 'screenfull'
1516

1617
import katex from 'katex'
@@ -51,8 +52,13 @@ app.use(directives)
5152
for (const [key, component] of Object.entries(ElementPlusIcons)) {
5253
app.component(key, component)
5354
}
55+
const locale_map: any = {
56+
'zh-CN': zhCn,
57+
'zh-Hant': zhTW,
58+
'en-US': enUs
59+
}
5460
app.use(ElementPlus, {
55-
locale: zhCn
61+
locale: locale_map[localStorage.getItem('MaxKB-locale') || 'zh-CN']
5662
})
5763

5864
app.use(router)

ui/src/request/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ instance.interceptors.request.use(
2525
}
2626
const { user } = useStore()
2727
const token = user.getToken()
28+
const language = user.getLanguage()
29+
config.headers['Accept-Language'] = `${language}`
2830
if (token) {
2931
config.headers['AUTHORIZATION'] = `${token}`
3032
}
@@ -208,7 +210,7 @@ export const postStream: (url: string, data?: unknown) => Promise<Result<any> |
208210
if (token) {
209211
headers['AUTHORIZATION'] = `${token}`
210212
}
211-
headers['Accept-Language'] = `${language}`
213+
headers['Accept-Language'] = `${language}`
212214
return fetch(url, {
213215
method: 'POST',
214216
body: data ? JSON.stringify(data) : undefined,

ui/src/stores/modules/application.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ import applicationXpackApi from '@/api/application-xpack'
44
import { type Ref } from 'vue'
55

66
import useUserStore from './user'
7-
87
const useApplicationStore = defineStore({
98
id: 'application',
109
state: () => ({
11-
location: `${window.location.origin}/ui/chat/`,
12-
userLanguage: ''
10+
location: `${window.location.origin}/ui/chat/`
1311
}),
1412
actions: {
1513
async asyncGetAllApplication() {
@@ -80,9 +78,10 @@ const useApplicationStore = defineStore({
8078
return new Promise((resolve, reject) => {
8179
applicationApi
8280
.getAppProfile(loading)
83-
.then((data) => {
84-
this.userLanguage = data.data?.language
85-
resolve(data)
81+
.then((res) => {
82+
sessionStorage.setItem('language', res.data?.language)
83+
84+
resolve(res)
8685
})
8786
.catch((error) => {
8887
reject(error)

ui/src/stores/modules/user.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import UserApi from '@/api/user'
66
import ThemeApi from '@/api/theme'
77
import { useElementPlusTheme } from 'use-element-plus-theme'
88
import { defaultPlatformSetting } from '@/utils/theme'
9-
import useApplicationStore from './application'
109
import { useLocalStorage } from '@vueuse/core'
1110
import { localeConfigKey } from '@/locales/index'
1211
export interface userStateTypes {
@@ -33,10 +32,9 @@ const useUserStore = defineStore({
3332
}),
3433
actions: {
3534
getLanguage() {
36-
const application = useApplicationStore()
3735
return this.userType === 1
38-
? this.userInfo?.language || localStorage.getItem('language')
39-
: application?.userLanguage
36+
? localStorage.getItem('MaxKB-locale')
37+
: sessionStorage.getItem('language')
4038
},
4139
showXpack() {
4240
return this.isXPack
@@ -127,7 +125,6 @@ const useUserStore = defineStore({
127125
return UserApi.profile().then(async (ok) => {
128126
this.userInfo = ok.data
129127
useLocalStorage(localeConfigKey, 'zh-CN').value = ok.data?.language
130-
// localStorage.setItem('language', ok.data?.language)
131128
return this.asyncGetProfile()
132129
})
133130
},
@@ -174,8 +171,8 @@ const useUserStore = defineStore({
174171
return new Promise((resolve, reject) => {
175172
UserApi.postLanguage({ language: lang }, loading)
176173
.then(async (ok) => {
174+
useLocalStorage(localeConfigKey, 'zh-CN').value = lang
177175
window.location.reload()
178-
179176
resolve(ok)
180177
})
181178
.catch((error) => {

ui/src/views/chat/index.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import { useRoute } from 'vue-router'
2424
import useStore from '@/stores'
2525
import Auth from '@/views/chat/auth/index.vue'
2626
import { hexToRgba } from '@/utils/theme'
27+
import { useI18n } from 'vue-i18n'
28+
const { locale } = useI18n({ useScope: 'global' })
2729
const route = useRoute()
2830
const { application, user } = useStore()
2931
@@ -78,6 +80,7 @@ const init_data_end = ref<boolean>(false)
7880
const applicationAvailable = ref<boolean>(true)
7981
function getAppProfile() {
8082
return application.asyncGetAppProfile(loading).then((res: any) => {
83+
locale.value = res.data?.language
8184
show_history.value = res.data?.show_history
8285
application_profile.value = res.data
8386
})

ui/src/views/login/index.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,11 @@ import type { FormInstance, FormRules } from 'element-plus'
106106
import useStore from '@/stores'
107107
import authApi from '@/api/auth-setting'
108108
import { MsgConfirm, MsgSuccess } from '@/utils/message'
109+
109110
import { t } from '@/locales'
110111
import QrCodeTab from '@/views/login/components/QrCodeTab.vue'
112+
import { useI18n } from 'vue-i18n'
113+
const { locale } = useI18n({ useScope: 'global' })
111114
const loading = ref<boolean>(false)
112115
const { user } = useStore()
113116
const router = useRouter()
@@ -212,6 +215,7 @@ const login = () => {
212215
user
213216
.login(loginMode.value, loginForm.value.username, loginForm.value.password)
214217
.then(() => {
218+
locale.value = localStorage.getItem('MaxKB-locale') || 'zh-CN'
215219
router.push({ name: 'home' })
216220
})
217221
.finally(() => (loading.value = false))

0 commit comments

Comments
 (0)