mirror of
https://github.com/veops/cmdb.git
synced 2025-08-25 21:21:06 +08:00
feat(ui): i18n - init language add getSystemLanguage request
This commit is contained in:
@@ -12,6 +12,7 @@ import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
|
|||||||
import enUS from 'ant-design-vue/lib/locale-provider/en_US'
|
import enUS from 'ant-design-vue/lib/locale-provider/en_US'
|
||||||
import { AppDeviceEnquire } from '@/utils/mixin'
|
import { AppDeviceEnquire } from '@/utils/mixin'
|
||||||
import { debounce } from './utils/util'
|
import { debounce } from './utils/util'
|
||||||
|
import { getSystemLanguage } from '@/api/system.js'
|
||||||
|
|
||||||
import { h } from 'snabbdom'
|
import { h } from 'snabbdom'
|
||||||
import { DomEditor, Boot } from '@wangeditor/editor'
|
import { DomEditor, Boot } from '@wangeditor/editor'
|
||||||
@@ -45,8 +46,7 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.SET_LOCALE(localStorage.getItem('ops_locale') || 'zh')
|
this.initLanguage()
|
||||||
this.$i18n.locale = localStorage.getItem('ops_locale') || 'zh'
|
|
||||||
this.timer = setInterval(() => {
|
this.timer = setInterval(() => {
|
||||||
this.setTime(new Date().getTime())
|
this.setTime(new Date().getTime())
|
||||||
}, 1000)
|
}, 1000)
|
||||||
@@ -200,6 +200,28 @@ export default {
|
|||||||
this.alive = true
|
this.alive = true
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
async initLanguage() {
|
||||||
|
let saveLocale = localStorage.getItem('ops_locale')
|
||||||
|
if (!saveLocale) {
|
||||||
|
let requestLanguage = ''
|
||||||
|
try {
|
||||||
|
const languageRes = await getSystemLanguage()
|
||||||
|
requestLanguage = languageRes?.language || ''
|
||||||
|
} catch (e) {
|
||||||
|
console.error('getSystemLanguage error:', e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// request language variable || user local system language
|
||||||
|
const userLanguage = requestLanguage || navigator.language || navigator.userLanguage
|
||||||
|
if (userLanguage.includes('zh')) {
|
||||||
|
saveLocale = 'zh'
|
||||||
|
} else {
|
||||||
|
saveLocale = 'en'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.SET_LOCALE(saveLocale)
|
||||||
|
this.$i18n.locale = saveLocale
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
8
cmdb-ui/src/api/system.js
Normal file
8
cmdb-ui/src/api/system.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { axios } from '@/utils/request'
|
||||||
|
|
||||||
|
export function getSystemLanguage() {
|
||||||
|
return axios({
|
||||||
|
url: '/common-setting/v1/system/language',
|
||||||
|
method: 'get',
|
||||||
|
})
|
||||||
|
}
|
Reference in New Issue
Block a user