diff --git a/ui/env.d.ts b/ui/env.d.ts
index be1f8389d..08bb5e826 100644
--- a/ui/env.d.ts
+++ b/ui/env.d.ts
@@ -1,5 +1,7 @@
///
declare module 'element-plus/dist/locale/zh-cn.mjs'
+declare module 'element-plus/dist/locale/en.mjs'
+declare module 'element-plus/dist/locale/zh-tw.mjs'
declare module 'markdown-it-task-lists'
declare module 'markdown-it-abbr'
declare module 'markdown-it-anchor'
diff --git a/ui/src/components/ai-chat/component/control/index.vue b/ui/src/components/ai-chat/component/control/index.vue
index 9827149f4..9674a7452 100644
--- a/ui/src/components/ai-chat/component/control/index.vue
+++ b/ui/src/components/ai-chat/component/control/index.vue
@@ -16,7 +16,7 @@ import bus from '@/bus'
import { ref, nextTick, onMounted } from 'vue'
import { t } from '@/locales'
const isOpen = ref(false)
-const eventVal = ref()
+const eventVal = ref({})
function getSelection() {
const selection = window.getSelection()
if (selection && selection.anchorNode == null) {
diff --git a/ui/src/main.ts b/ui/src/main.ts
index a93fe9ea9..69e220b78 100644
--- a/ui/src/main.ts
+++ b/ui/src/main.ts
@@ -2,6 +2,8 @@ import '@/styles/index.scss'
import ElementPlus from 'element-plus'
import * as ElementPlusIcons from '@element-plus/icons-vue'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
+import enUs from 'element-plus/dist/locale/en.mjs'
+import zhTW from 'element-plus/dist/locale/zh-tw.mjs'
import { createApp } from 'vue'
import { store } from '@/stores'
import directives from '@/directives'
@@ -10,7 +12,6 @@ import router from '@/router'
import Components from '@/components'
import i18n from './locales'
import { config } from 'md-editor-v3'
-
import screenfull from 'screenfull'
import katex from 'katex'
@@ -51,8 +52,13 @@ app.use(directives)
for (const [key, component] of Object.entries(ElementPlusIcons)) {
app.component(key, component)
}
+const locale_map: any = {
+ 'zh-CN': zhCn,
+ 'zh-Hant': zhTW,
+ 'en-US': enUs
+}
app.use(ElementPlus, {
- locale: zhCn
+ locale: locale_map[localStorage.getItem('MaxKB-locale') || 'zh-CN']
})
app.use(router)
diff --git a/ui/src/request/index.ts b/ui/src/request/index.ts
index 56a491518..d57928219 100644
--- a/ui/src/request/index.ts
+++ b/ui/src/request/index.ts
@@ -25,6 +25,8 @@ instance.interceptors.request.use(
}
const { user } = useStore()
const token = user.getToken()
+ const language = user.getLanguage()
+ config.headers['Accept-Language'] = `${language}`
if (token) {
config.headers['AUTHORIZATION'] = `${token}`
}
@@ -208,7 +210,7 @@ export const postStream: (url: string, data?: unknown) => Promise |
if (token) {
headers['AUTHORIZATION'] = `${token}`
}
- headers['Accept-Language'] = `${language}`
+ headers['Accept-Language'] = `${language}`
return fetch(url, {
method: 'POST',
body: data ? JSON.stringify(data) : undefined,
diff --git a/ui/src/stores/modules/application.ts b/ui/src/stores/modules/application.ts
index 359f952b5..3d30e62dd 100644
--- a/ui/src/stores/modules/application.ts
+++ b/ui/src/stores/modules/application.ts
@@ -4,12 +4,10 @@ import applicationXpackApi from '@/api/application-xpack'
import { type Ref } from 'vue'
import useUserStore from './user'
-
const useApplicationStore = defineStore({
id: 'application',
state: () => ({
- location: `${window.location.origin}/ui/chat/`,
- userLanguage: ''
+ location: `${window.location.origin}/ui/chat/`
}),
actions: {
async asyncGetAllApplication() {
@@ -80,9 +78,10 @@ const useApplicationStore = defineStore({
return new Promise((resolve, reject) => {
applicationApi
.getAppProfile(loading)
- .then((data) => {
- this.userLanguage = data.data?.language
- resolve(data)
+ .then((res) => {
+ sessionStorage.setItem('language', res.data?.language)
+
+ resolve(res)
})
.catch((error) => {
reject(error)
diff --git a/ui/src/stores/modules/user.ts b/ui/src/stores/modules/user.ts
index 740e0cd22..0be566b12 100644
--- a/ui/src/stores/modules/user.ts
+++ b/ui/src/stores/modules/user.ts
@@ -6,7 +6,6 @@ import UserApi from '@/api/user'
import ThemeApi from '@/api/theme'
import { useElementPlusTheme } from 'use-element-plus-theme'
import { defaultPlatformSetting } from '@/utils/theme'
-import useApplicationStore from './application'
import { useLocalStorage } from '@vueuse/core'
import { localeConfigKey } from '@/locales/index'
export interface userStateTypes {
@@ -33,10 +32,9 @@ const useUserStore = defineStore({
}),
actions: {
getLanguage() {
- const application = useApplicationStore()
return this.userType === 1
- ? this.userInfo?.language || localStorage.getItem('language')
- : application?.userLanguage
+ ? localStorage.getItem('MaxKB-locale')
+ : sessionStorage.getItem('language')
},
showXpack() {
return this.isXPack
@@ -127,7 +125,6 @@ const useUserStore = defineStore({
return UserApi.profile().then(async (ok) => {
this.userInfo = ok.data
useLocalStorage(localeConfigKey, 'zh-CN').value = ok.data?.language
- // localStorage.setItem('language', ok.data?.language)
return this.asyncGetProfile()
})
},
@@ -174,8 +171,8 @@ const useUserStore = defineStore({
return new Promise((resolve, reject) => {
UserApi.postLanguage({ language: lang }, loading)
.then(async (ok) => {
+ useLocalStorage(localeConfigKey, 'zh-CN').value = lang
window.location.reload()
-
resolve(ok)
})
.catch((error) => {
diff --git a/ui/src/views/chat/index.vue b/ui/src/views/chat/index.vue
index 36b8e4473..89bff9b06 100644
--- a/ui/src/views/chat/index.vue
+++ b/ui/src/views/chat/index.vue
@@ -24,6 +24,8 @@ import { useRoute } from 'vue-router'
import useStore from '@/stores'
import Auth from '@/views/chat/auth/index.vue'
import { hexToRgba } from '@/utils/theme'
+import { useI18n } from 'vue-i18n'
+const { locale } = useI18n({ useScope: 'global' })
const route = useRoute()
const { application, user } = useStore()
@@ -78,6 +80,7 @@ const init_data_end = ref(false)
const applicationAvailable = ref(true)
function getAppProfile() {
return application.asyncGetAppProfile(loading).then((res: any) => {
+ locale.value = res.data?.language
show_history.value = res.data?.show_history
application_profile.value = res.data
})
diff --git a/ui/src/views/login/index.vue b/ui/src/views/login/index.vue
index 3b1c9e8a4..67e15a698 100644
--- a/ui/src/views/login/index.vue
+++ b/ui/src/views/login/index.vue
@@ -106,8 +106,11 @@ import type { FormInstance, FormRules } from 'element-plus'
import useStore from '@/stores'
import authApi from '@/api/auth-setting'
import { MsgConfirm, MsgSuccess } from '@/utils/message'
+
import { t } from '@/locales'
import QrCodeTab from '@/views/login/components/QrCodeTab.vue'
+import { useI18n } from 'vue-i18n'
+const { locale } = useI18n({ useScope: 'global' })
const loading = ref(false)
const { user } = useStore()
const router = useRouter()
@@ -212,6 +215,7 @@ const login = () => {
user
.login(loginMode.value, loginForm.value.username, loginForm.value.password)
.then(() => {
+ locale.value = localStorage.getItem('MaxKB-locale') || 'zh-CN'
router.push({ name: 'home' })
})
.finally(() => (loading.value = false))