mirror of
https://github.com/veops/cmdb.git
synced 2025-08-11 17:38:40 +08:00
add basic
This commit is contained in:
66
cmdb-ui/src/locales/index.js
Normal file
66
cmdb-ui/src/locales/index.js
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
import Vue from 'vue'
|
||||
import VueI18n from 'vue-i18n'
|
||||
// default language
|
||||
import enUS from './lang/en-US'
|
||||
// change default accept-language
|
||||
import { axios } from '@/utils/request'
|
||||
|
||||
Vue.use(VueI18n)
|
||||
|
||||
export const defaultLang = 'en-US'
|
||||
|
||||
const messages = {
|
||||
'en-US': {
|
||||
...enUS
|
||||
}
|
||||
}
|
||||
|
||||
const i18n = new VueI18n({
|
||||
locale: defaultLang,
|
||||
fallbackLocale: defaultLang,
|
||||
messages
|
||||
})
|
||||
|
||||
export default i18n
|
||||
|
||||
const loadedLanguages = [defaultLang]
|
||||
|
||||
// 从缓存設置中加载当前语言
|
||||
// if (Vue.ls.get('lang') !== null && defaultLang !== Vue.ls.get('lang')) {
|
||||
// loadLanguageAsync(localStorage.lang)
|
||||
// }
|
||||
|
||||
function setI18nLanguage (lang) {
|
||||
i18n.locale = lang
|
||||
axios.defaults.headers.common['Accept-Language'] = lang
|
||||
document.querySelector('html').setAttribute('lang', lang)
|
||||
return lang
|
||||
}
|
||||
|
||||
/**
|
||||
* i18n Render
|
||||
* @param key
|
||||
* @returns rendered string
|
||||
*/
|
||||
export function i18nRender (key) {
|
||||
return i18n.t(key)
|
||||
}
|
||||
|
||||
export function loadLanguageAsync (lang = defaultLang) {
|
||||
return new Promise(resolve => {
|
||||
// 缓存语言设置
|
||||
Vue.ls.set('lang', lang)
|
||||
if (i18n.locale !== lang) {
|
||||
if (!loadedLanguages.includes(lang)) {
|
||||
return import(/* webpackChunkName: "lang-[request]" */ `./lang/${lang}`).then(msg => {
|
||||
i18n.setLocaleMessage(lang, msg.default)
|
||||
loadedLanguages.push(lang)
|
||||
return setI18nLanguage(lang)
|
||||
})
|
||||
}
|
||||
return resolve(setI18nLanguage(lang))
|
||||
}
|
||||
return resolve(lang)
|
||||
})
|
||||
}
|
13
cmdb-ui/src/locales/lang/en-US.js
Normal file
13
cmdb-ui/src/locales/lang/en-US.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import enUS from 'ant-design-vue/es/locale-provider/en_US'
|
||||
|
||||
export default {
|
||||
antLocale: enUS,
|
||||
menu: {
|
||||
preference: 'Preference',
|
||||
relationViews: 'RelationViews',
|
||||
treeViews: 'Treeviews',
|
||||
batch: 'Batch',
|
||||
ciType: 'CiType',
|
||||
acl: 'ACL'
|
||||
}
|
||||
}
|
12
cmdb-ui/src/locales/lang/zh-CN.js
Normal file
12
cmdb-ui/src/locales/lang/zh-CN.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import zhCN from 'ant-design-vue/es/locale-provider/zh_CN'
|
||||
export default {
|
||||
antLocale: zhCN,
|
||||
menu: {
|
||||
preference: '我的订阅',
|
||||
relationViews: '关系视图',
|
||||
treeViews: '树状视图',
|
||||
batch: '批量导入',
|
||||
ciType: '模型配置',
|
||||
acl: '权限管理'
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user