✨ add i18n
Former-commit-id: e40632a3129a3147d4692474f05fcac1a8fb05da [formerly e40632a3129a3147d4692474f05fcac1a8fb05da [formerly e40632a3129a3147d4692474f05fcac1a8fb05da [formerly e40632a3129a3147d4692474f05fcac1a8fb05da [formerly 8a560e505164fe5718e1f386ecd8c84d213726b1 [formerly 0582bf632cbd9db5164fb2c454399fd1bd64ba41]]]]] Former-commit-id: d0e35c73fc91d65ac612adf939e15f2c05a6dc1f Former-commit-id: e6f9e3c3173dc757fd348cfc493055cdf4ed55a7 Former-commit-id: 3ea8c7bf97ab2e1b91986c7cd1a92da4200ecbc0 [formerly f4ffd12918a98e51b9f5f53a0102254e12ccc634] Former-commit-id: 5eddfc5487865adcbef1d176ab1fabf305614efc Former-commit-id: 044b0bf737fed573bd305b036c236b0a227bf0e1 Former-commit-id: f85fe58ea89d29b4579023de9829347012d29bc6 Former-commit-id: c91fbfc5efab828f43c8c51216c604a3987973b4 Former-commit-id: d96ee1048ea756123890a74af896b14a851c375d
This commit is contained in:
17
src/components/HelloI18n.vue
Normal file
17
src/components/HelloI18n.vue
Normal file
@@ -0,0 +1,17 @@
|
||||
<template>
|
||||
<p>{{ $t('hello') }}</p>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'HelloI18n'
|
||||
}
|
||||
</script>
|
||||
|
||||
<i18n>
|
||||
{
|
||||
"en": {
|
||||
"hello": "Hello i18n in SFC!"
|
||||
}
|
||||
}
|
||||
</i18n>
|
||||
23
src/i18n.js
Normal file
23
src/i18n.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import Vue from 'vue'
|
||||
import VueI18n from 'vue-i18n'
|
||||
|
||||
Vue.use(VueI18n)
|
||||
|
||||
function loadLocaleMessages () {
|
||||
const locales = require.context('./locales', true, /[A-Za-z0-9-_,\s]+\.json$/i)
|
||||
const messages = {}
|
||||
locales.keys().forEach(key => {
|
||||
const matched = key.match(/([A-Za-z0-9-_]+)\./i)
|
||||
if (matched && matched.length > 1) {
|
||||
const locale = matched[1]
|
||||
messages[locale] = locales(key)
|
||||
}
|
||||
})
|
||||
return messages
|
||||
}
|
||||
|
||||
export default new VueI18n({
|
||||
locale: process.env.VUE_APP_I18N_LOCALE || 'en',
|
||||
fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en',
|
||||
messages: loadLocaleMessages()
|
||||
})
|
||||
3
src/locales/en.json
Normal file
3
src/locales/en.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"message": "hello i18n !!"
|
||||
}
|
||||
3
src/locales/zh.json
Normal file
3
src/locales/zh.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"message": "hello i18n !!"
|
||||
}
|
||||
@@ -31,6 +31,7 @@ import d2VueFiltersDayjs from '@d2-admin/filters-dayjs'
|
||||
import router from './router'
|
||||
import { menuHeader, menuAside } from '@/menu'
|
||||
import { frameInRoutes } from '@/router/routes'
|
||||
import i18n from './i18n'
|
||||
|
||||
// 核心插件
|
||||
Vue.use(d2Admin)
|
||||
@@ -52,6 +53,7 @@ new Vue({
|
||||
router,
|
||||
store,
|
||||
render: h => h(App),
|
||||
|
||||
created () {
|
||||
// 处理路由 得到每一级的路由设置
|
||||
this.$store.commit('d2admin/page/init', frameInRoutes)
|
||||
@@ -60,6 +62,7 @@ new Vue({
|
||||
// 初始化菜单搜索功能
|
||||
this.$store.commit('d2admin/search/init', menuHeader)
|
||||
},
|
||||
|
||||
mounted () {
|
||||
// 展示系统信息
|
||||
this.$store.commit('d2admin/releases/versionShow')
|
||||
@@ -70,6 +73,9 @@ new Vue({
|
||||
// 初始化全屏监听
|
||||
this.$store.dispatch('d2admin/fullscreen/listen')
|
||||
},
|
||||
|
||||
i18n,
|
||||
|
||||
watch: {
|
||||
// 检测路由变化切换侧边栏内容
|
||||
'$route.matched': {
|
||||
|
||||
Reference in New Issue
Block a user