add i18n basic structure

This commit is contained in:
shaohaojiecoder 2020-02-09 17:54:57 +08:00
parent e336b31902
commit 4e0dc1282f
4 changed files with 20 additions and 11 deletions

View File

@ -3,7 +3,7 @@
<div class="content-box">
<a href="https://github.com/pycook/cmdb" target="_blank">
<span class="action">
源代码 -> <a-icon type="github" style="font-size: 20px; color: #002140"></a-icon>
{{ $t('tip.sourceCode') }} -> <a-icon type="github" style="font-size: 20px; color: #002140"></a-icon>
</span>
</a>
<!-- <a href="https://pro.loacg.com/docs/getting-started" target="_blank">
@ -39,7 +39,7 @@
</a-menu-item>
</a-menu>
</a-dropdown>
<lang-select />
<lang-select v-if="showLocale" />
</div>
</div>
</template>
@ -48,12 +48,18 @@
import NoticeIcon from '@/components/NoticeIcon'
import { mapActions, mapGetters } from 'vuex'
import LangSelect from '@/components/tools/LangSelect'
import { showLocale } from '@/locales'
export default {
name: 'UserMenu',
components: {
NoticeIcon, LangSelect
},
data () {
return {
showLocale: showLocale
}
},
methods: {
...mapActions(['Logout']),
...mapGetters(['nickname', 'avatar']),

View File

@ -3,16 +3,21 @@ import Vue from 'vue'
import VueI18n from 'vue-i18n'
// default language
import enUS from './lang/en-US'
import zhCN from './lang/zh-CN'
// change default accept-language
import { axios } from '@/utils/request'
Vue.use(VueI18n)
export const defaultLang = 'en-US'
export const defaultLang = 'zh-CN'
export const showLocale = true
const messages = {
'en-US': {
...enUS
},
'zh-CN': {
...zhCN
}
}
@ -27,9 +32,6 @@ 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
@ -38,11 +40,6 @@ function setI18nLanguage (lang) {
return lang
}
/**
* i18n Render
* @param key
* @returns rendered string
*/
export function i18nRender (key) {
return i18n.t(key)
}
@ -64,3 +61,7 @@ export function loadLanguageAsync (lang = defaultLang) {
return resolve(lang)
})
}
// if (Vue.ls.get('lang') !== null && defaultLang !== Vue.ls.get('lang')) {
// loadLanguageAsync(localStorage.lang)
// }

View File

@ -32,6 +32,7 @@ export default {
upload: 'Upload'
},
tip: {
sourceCode: 'view on',
subscribed: 'Subscribed',
unsubscribed: 'Unsubscribed',
unfold: 'Unfold',

View File

@ -32,6 +32,7 @@ export default {
upload: '上传'
},
tip: {
sourceCode: '源代码',
subscribed: '已订阅',
unsubscribed: '未订阅',
unfold: '展开',