mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
Merge branch 'pr@main@i18n'
This commit is contained in:
commit
b1cd9578fc
|
|
@ -1,5 +1,7 @@
|
|||
/// <reference types="vite/client" />
|
||||
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'
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import bus from '@/bus'
|
|||
import { ref, nextTick, onMounted } from 'vue'
|
||||
import { t } from '@/locales'
|
||||
const isOpen = ref<boolean>(false)
|
||||
const eventVal = ref()
|
||||
const eventVal = ref<any>({})
|
||||
function getSelection() {
|
||||
const selection = window.getSelection()
|
||||
if (selection && selection.anchorNode == null) {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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<Result<any> |
|
|||
if (token) {
|
||||
headers['AUTHORIZATION'] = `${token}`
|
||||
}
|
||||
headers['Accept-Language'] = `${language}`
|
||||
headers['Accept-Language'] = `${language}`
|
||||
return fetch(url, {
|
||||
method: 'POST',
|
||||
body: data ? JSON.stringify(data) : undefined,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -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<boolean>(false)
|
|||
const applicationAvailable = ref<boolean>(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
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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<boolean>(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))
|
||||
|
|
|
|||
Loading…
Reference in New Issue