feat: i18n

This commit is contained in:
wangdan-fit2cloud 2025-01-20 20:50:03 +08:00
parent 9e5352b8d7
commit 059ffc1b01
5 changed files with 17 additions and 12 deletions

View File

@ -0,0 +1,4 @@
export default {
createChat: 'Create Chat',
history: 'History record'
}

View File

@ -1,4 +1,4 @@
import chat from './ai-chat'
export default {
};
chat,
}

View File

@ -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)

View File

@ -33,10 +33,9 @@ const useUserStore = defineStore({
}),
actions: {
getLanguage() {
const application = useApplicationStore()
return this.userType === 1
? this.userInfo?.language || localStorage.getItem('MaxKB-locale')
: application?.userLanguage
? localStorage.getItem('MaxKB-locale')
: sessionStorage.getItem('language')
},
showXpack() {
return this.isXPack

View File

@ -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
})