perf: 修改翻译方式

This commit is contained in:
ibuler 2024-01-10 18:31:38 +08:00
parent 1b60735808
commit 3eb113a5cb
6 changed files with 50 additions and 3714 deletions

View File

@ -5,6 +5,8 @@ import VueI18n from 'vue-i18n'
import messages from './langs'
import date from './date'
import VueCookie from 'vue-cookie'
import axios from 'axios'
import store from '@/store'
Vue.use(VueI18n)
const cookieLang = VueCookie.get('django_language')
@ -25,4 +27,21 @@ Vue.prototype.$tr = (key) => {
return i18n.t('' + key)
}
axios.get(`/api/v1/settings/i18n/lina/?lang=${lang}`)
.then((res) => {
if (res.status !== 200) {
return
}
const data = res.data
for (const key in data) {
if (data.hasOwnProperty(key)) {
console.log('i18n loaded123123123: ', key, data[key])
i18n.mergeLocaleMessage(key, data[key])
}
}
})
.finally(() => {
store.dispatch('app/setI18nLoaded', true)
})
export default i18n

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@ import zh from './zh.json'
import en from './en.json'
import ja from './ja.json'
export default {
const messages = {
zh: {
...zhLocale,
...zh
@ -19,3 +19,5 @@ export default {
...ja
}
}
export default messages

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,8 @@ const state = {
// 默认需要展开的菜单
defaultOpensMenu: ['/audit/sessions', '/audit/logs', '/workbench/ops'],
device: 'desktop',
inited: false
inited: false,
i18nLoaded: false
}
const mutations = {
@ -31,6 +32,9 @@ const mutations = {
},
SET_INIT: (state, value) => {
state.inited = value
},
SET_I18N_LOADED: (state, value) => {
state.i18nLoaded = value
}
}
@ -49,6 +53,9 @@ const actions = {
},
reset({ commit }) {
commit('SET_INIT', false)
},
setI18nLoaded({ commit }, value) {
commit('SET_I18N_LOADED', value)
}
}

View File

@ -169,6 +169,23 @@ export async function changeCurrentViewIfNeed({ to, from, next }) {
return new Promise((resolve, reject) => reject(''))
}
async function onI18nLoaded() {
return new Promise(resolve => {
const load = store.state.app.i18nLoaded
if (load) {
resolve()
}
const itv = setInterval(() => {
const load = store.state.app.i18nLoaded
if (load) {
clearInterval(itv)
console.log('I18n loaded')
resolve()
}
}, 100)
})
}
export async function startup({ to, from, next }) {
// if (store.getters.inited) { return true }
if (store.getters.inited) {
@ -185,6 +202,7 @@ export async function startup({ to, from, next }) {
await changeCurrentOrgIfNeed({ to, from, next })
await generatePageRoutes({ to, from, next })
await checkUserFirstLogin({ to, from, next })
await onI18nLoaded()
await store.dispatch('assets/getAssetCategories')
return true
}