mirror of
https://github.com/jumpserver/lina.git
synced 2025-08-05 16:55:36 +00:00
perf: 修改翻译方式
This commit is contained in:
parent
1b60735808
commit
3eb113a5cb
@ -5,6 +5,8 @@ import VueI18n from 'vue-i18n'
|
|||||||
import messages from './langs'
|
import messages from './langs'
|
||||||
import date from './date'
|
import date from './date'
|
||||||
import VueCookie from 'vue-cookie'
|
import VueCookie from 'vue-cookie'
|
||||||
|
import axios from 'axios'
|
||||||
|
import store from '@/store'
|
||||||
|
|
||||||
Vue.use(VueI18n)
|
Vue.use(VueI18n)
|
||||||
const cookieLang = VueCookie.get('django_language')
|
const cookieLang = VueCookie.get('django_language')
|
||||||
@ -25,4 +27,21 @@ Vue.prototype.$tr = (key) => {
|
|||||||
return i18n.t('' + 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
|
export default i18n
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,7 @@ import zh from './zh.json'
|
|||||||
import en from './en.json'
|
import en from './en.json'
|
||||||
import ja from './ja.json'
|
import ja from './ja.json'
|
||||||
|
|
||||||
export default {
|
const messages = {
|
||||||
zh: {
|
zh: {
|
||||||
...zhLocale,
|
...zhLocale,
|
||||||
...zh
|
...zh
|
||||||
@ -19,3 +19,5 @@ export default {
|
|||||||
...ja
|
...ja
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default messages
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -8,7 +8,8 @@ const state = {
|
|||||||
// 默认需要展开的菜单
|
// 默认需要展开的菜单
|
||||||
defaultOpensMenu: ['/audit/sessions', '/audit/logs', '/workbench/ops'],
|
defaultOpensMenu: ['/audit/sessions', '/audit/logs', '/workbench/ops'],
|
||||||
device: 'desktop',
|
device: 'desktop',
|
||||||
inited: false
|
inited: false,
|
||||||
|
i18nLoaded: false
|
||||||
}
|
}
|
||||||
|
|
||||||
const mutations = {
|
const mutations = {
|
||||||
@ -31,6 +32,9 @@ const mutations = {
|
|||||||
},
|
},
|
||||||
SET_INIT: (state, value) => {
|
SET_INIT: (state, value) => {
|
||||||
state.inited = value
|
state.inited = value
|
||||||
|
},
|
||||||
|
SET_I18N_LOADED: (state, value) => {
|
||||||
|
state.i18nLoaded = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +53,9 @@ const actions = {
|
|||||||
},
|
},
|
||||||
reset({ commit }) {
|
reset({ commit }) {
|
||||||
commit('SET_INIT', false)
|
commit('SET_INIT', false)
|
||||||
|
},
|
||||||
|
setI18nLoaded({ commit }, value) {
|
||||||
|
commit('SET_I18N_LOADED', value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,6 +169,23 @@ export async function changeCurrentViewIfNeed({ to, from, next }) {
|
|||||||
return new Promise((resolve, reject) => reject(''))
|
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 }) {
|
export async function startup({ to, from, next }) {
|
||||||
// if (store.getters.inited) { return true }
|
// if (store.getters.inited) { return true }
|
||||||
if (store.getters.inited) {
|
if (store.getters.inited) {
|
||||||
@ -185,6 +202,7 @@ export async function startup({ to, from, next }) {
|
|||||||
await changeCurrentOrgIfNeed({ to, from, next })
|
await changeCurrentOrgIfNeed({ to, from, next })
|
||||||
await generatePageRoutes({ to, from, next })
|
await generatePageRoutes({ to, from, next })
|
||||||
await checkUserFirstLogin({ to, from, next })
|
await checkUserFirstLogin({ to, from, next })
|
||||||
|
await onI18nLoaded()
|
||||||
await store.dispatch('assets/getAssetCategories')
|
await store.dispatch('assets/getAssetCategories')
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user