mirror of https://github.com/veops/cmdb.git
Merge pull request #33 from shaohaojiecoder/i18n
fix local storage for defalut lang
This commit is contained in:
commit
a188218818
|
@ -48,7 +48,7 @@
|
||||||
import NoticeIcon from '@/components/NoticeIcon'
|
import NoticeIcon from '@/components/NoticeIcon'
|
||||||
import { mapActions, mapGetters } from 'vuex'
|
import { mapActions, mapGetters } from 'vuex'
|
||||||
import LangSelect from '@/components/tools/LangSelect'
|
import LangSelect from '@/components/tools/LangSelect'
|
||||||
import { showLocale } from '@/locales'
|
import config from '@/config/defaultSettings'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'UserMenu',
|
name: 'UserMenu',
|
||||||
|
@ -57,7 +57,7 @@ export default {
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
showLocale: showLocale
|
showLocale: config.showLocale
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
showLocale: true,
|
||||||
|
defaultLang: 'zh-CN',
|
||||||
useSSO: false,
|
useSSO: false,
|
||||||
primaryColor: '#1890ff', // primary color of ant design
|
primaryColor: '#1890ff', // primary color of ant design
|
||||||
navTheme: 'dark', // theme for nav menu
|
navTheme: 'dark', // theme for nav menu
|
||||||
|
|
|
@ -6,12 +6,10 @@ import enUS from './lang/en-US'
|
||||||
import zhCN from './lang/zh-CN'
|
import zhCN from './lang/zh-CN'
|
||||||
// change default accept-language
|
// change default accept-language
|
||||||
import { axios } from '@/utils/request'
|
import { axios } from '@/utils/request'
|
||||||
|
import config from '@/config/defaultSettings'
|
||||||
|
|
||||||
Vue.use(VueI18n)
|
Vue.use(VueI18n)
|
||||||
|
|
||||||
export const defaultLang = 'zh-CN'
|
|
||||||
export const showLocale = true
|
|
||||||
|
|
||||||
const messages = {
|
const messages = {
|
||||||
'en-US': {
|
'en-US': {
|
||||||
...enUS
|
...enUS
|
||||||
|
@ -22,14 +20,14 @@ const messages = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const i18n = new VueI18n({
|
const i18n = new VueI18n({
|
||||||
locale: defaultLang,
|
locale: config.defaultLang,
|
||||||
fallbackLocale: defaultLang,
|
fallbackLocale: config.defaultLang,
|
||||||
messages
|
messages
|
||||||
})
|
})
|
||||||
|
|
||||||
export default i18n
|
export default i18n
|
||||||
|
|
||||||
const loadedLanguages = [defaultLang]
|
const loadedLanguages = [config.defaultLang]
|
||||||
|
|
||||||
function setI18nLanguage (lang) {
|
function setI18nLanguage (lang) {
|
||||||
i18n.locale = lang
|
i18n.locale = lang
|
||||||
|
@ -42,9 +40,9 @@ export function i18nRender (key) {
|
||||||
return i18n.t(key)
|
return i18n.t(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadLanguageAsync (lang = defaultLang) {
|
export function loadLanguageAsync (lang = config.defaultLang) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
Vue.ls.set('lang', lang)
|
localStorage.setItem('lang', lang)
|
||||||
if (i18n.locale !== lang) {
|
if (i18n.locale !== lang) {
|
||||||
if (!loadedLanguages.includes(lang)) {
|
if (!loadedLanguages.includes(lang)) {
|
||||||
return import(/* webpackChunkName: "lang-[request]" */ `./lang/${lang}`).then(msg => {
|
return import(/* webpackChunkName: "lang-[request]" */ `./lang/${lang}`).then(msg => {
|
||||||
|
@ -59,6 +57,6 @@ export function loadLanguageAsync (lang = defaultLang) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (Vue.ls.get('lang') !== null && defaultLang !== Vue.ls.get('lang')) {
|
if (localStorage.getItem('lang') !== null && config.defaultLang !== localStorage.getItem('lang')) {
|
||||||
// loadLanguageAsync(localStorage.lang)
|
loadLanguageAsync(localStorage.lang)
|
||||||
// }
|
}
|
||||||
|
|
Loading…
Reference in New Issue