Former-commit-id: bb6f09e83ff6e530a4bf49d46c6b0d1168a93246
This commit is contained in:
FairyEver
2019-09-25 16:13:46 +08:00
parent 0112b7d514
commit 0304d22852
10 changed files with 88 additions and 31 deletions
+10 -4
View File
@@ -7,13 +7,17 @@ Vue.use(VueI18n)
function loadLocaleMessages () { function loadLocaleMessages () {
const locales = require.context('./locales', true, /[A-Za-z0-9-_,\s]+\.json$/i) const locales = require.context('./locales', true, /[A-Za-z0-9-_,\s]+\.json$/i)
const messages = {} const messages = {}
locales.keys().forEach(key => { for (const key of locales.keys()) {
const matched = key.match(/([A-Za-z0-9-_]+)\./i) const matched = key.match(/([A-Za-z0-9-_]+)\./i)
if (matched && matched.length > 1) { if (matched && matched.length > 1) {
const locale = matched[1] const locale = matched[1]
messages[locale] = locales(key) const localeElementUI = require(`element-ui/lib/locale/lang/${locales(key)._element}`)
messages[locale] = {
...locales(key),
...localeElementUI ? localeElementUI.default : {}
}
} }
}) }
return messages return messages
} }
@@ -24,8 +28,10 @@ Vue.prototype.$languages = Object.keys(messages).map(langlage => ({
value: langlage value: langlage
})) }))
export default new VueI18n({ const i18n = new VueI18n({
locale: util.cookies.get('lang') || process.env.VUE_APP_I18N_LOCALE, locale: util.cookies.get('lang') || process.env.VUE_APP_I18N_LOCALE,
fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE, fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE,
messages messages
}) })
export default i18n
@@ -19,24 +19,10 @@
</template> </template>
<script> <script>
import localeMixin from '@/locales/mixin.js'
export default { export default {
methods: { mixins: [
onChangeLocale (command) { localeMixin
this.$i18n.locale = command ]
let message = `当前语言:${this.$t('_name')} [ ${this.$i18n.locale} ]`
if (!['TRAVIS', 'NETLIFY'].includes(process.env.VUE_APP_BUILD_MODE)) {
message = [
`当前语言:${this.$t('_name')} [ ${this.$i18n.locale} ]`,
`仅提供切换功能,没有配置具体的语言数据 `,
`文档参考:<a class="el-link el-link--primary is-underline" target="_blank" href="https://doc.d2admin.fairyever.com/zh/sys-locales/">《国际化 | D2Admin》</a>`
].join('<br/>')
}
this.$notify({
title: '语言变更',
dangerouslyUseHTMLString: true,
message
})
}
}
} }
</script> </script>
+11 -1
View File
@@ -1,3 +1,13 @@
{ {
"_name": "English" "_element": "en",
"_name": "English",
"page": {
"demo": {
"playground": {
"locales": {
"text": "D2Admin is a fully open source and free enterprise back-end product front-end integration solution, using the latest front-end technology stack, has prepared most of the project preparations, and with a lot of sample code to help the management system agile development."
}
}
}
}
} }
+11 -1
View File
@@ -1,3 +1,13 @@
{ {
"_name": "日本語" "_element": "ja",
"_name": "日本語",
"page": {
"demo": {
"playground": {
"locales": {
"text": "D2Adminは、最新のフロントエンドテクノロジースタックを使用した、完全にオープンソースの無料エンタープライズバックエンド製品フロントエンド統合ソリューションであり、プロジェクトのほとんどの準備を整えており、システムのアジャイル開発の管理に役立つ多くのサンプルコードを備えています。"
}
}
}
}
} }
+20
View File
@@ -0,0 +1,20 @@
export default {
methods: {
onChangeLocale (command) {
this.$i18n.locale = command
let message = `当前语言:${this.$t('_name')} [ ${this.$i18n.locale} ]`
if (['TRAVIS', 'NETLIFY'].includes(process.env.VUE_APP_BUILD_MODE)) {
message = [
`当前语言:${this.$t('_name')} [ ${this.$i18n.locale} ]`,
`仅提供切换功能,没有配置具体的语言数据 `,
`文档参考:<a class="el-link el-link--primary is-underline" target="_blank" href="https://doc.d2admin.fairyever.com/zh/sys-locales/">《国际化 | D2Admin》</a>`
].join('<br/>')
}
this.$notify({
title: '语言变更',
dangerouslyUseHTMLString: true,
message
})
}
}
}
+11 -1
View File
@@ -1,3 +1,13 @@
{ {
"_name": "简体中文" "_element": "zh-CN",
"_name": "简体中文",
"page": {
"demo": {
"playground": {
"locales": {
"text": "D2Admin 是一个完全 开源免费 的企业中后台产品前端集成方案,使用最新的前端技术栈,已经做好大部分项目前期准备工作,并且带有大量示例代码,助力管理系统敏捷开发。"
}
}
}
}
} }
+11 -1
View File
@@ -1,3 +1,13 @@
{ {
"_name": "繁體中文" "_element": "zh-TW",
"_name": "繁體中文",
"page": {
"demo": {
"playground": {
"locales": {
"text": "D2Admin 是一個完全 開源免費 的企業中後台產品前端集成方案,使用最新的前端技術棧,已經做好大部分項目前期準備工作,並且帶有大量示例代碼,助力管理系統敏捷開發。"
}
}
}
}
} }
+5 -1
View File
@@ -7,6 +7,8 @@ import 'flex.css'
import '@/components' import '@/components'
// svg 图标 // svg 图标
import '@/assets/svg-icons' import '@/assets/svg-icons'
// 国际化
import i18n from '@/i18n.js'
// 功能插件 // 功能插件
import pluginError from '@/plugin/error' import pluginError from '@/plugin/error'
@@ -27,7 +29,9 @@ export default {
// 构建时间 // 构建时间
Vue.prototype.$buildTime = process.env.VUE_APP_BUILD_TIME Vue.prototype.$buildTime = process.env.VUE_APP_BUILD_TIME
// Element // Element
Vue.use(ElementUI) Vue.use(ElementUI, {
i18n: (key, value) => i18n.t(key, value)
})
// 插件 // 插件
Vue.use(pluginError) Vue.use(pluginError)
Vue.use(pluginLog) Vue.use(pluginLog)
@@ -70,8 +70,6 @@ export default {
if (confirm) { if (confirm) {
commit('d2admin/gray/set', true, { root: true }) commit('d2admin/gray/set', true, { root: true })
MessageBox.confirm('确定要注销当前用户吗', '注销用户', { MessageBox.confirm('确定要注销当前用户吗', '注销用户', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning' type: 'warning'
}) })
.then(() => { .then(() => {
+5 -2
View File
@@ -85,8 +85,7 @@
<a <a
v-for="language in $languages" v-for="language in $languages"
:key="language.value" :key="language.value"
:command="language.value" @click="onChangeLocale(language.value)">
@click="$i18n.locale = language.value">
{{ language.label }} {{ language.label }}
</a> </a>
</p> </p>
@@ -125,7 +124,11 @@
<script> <script>
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { mapActions } from 'vuex' import { mapActions } from 'vuex'
import localeMixin from '@/locales/mixin.js'
export default { export default {
mixins: [
localeMixin
],
data () { data () {
return { return {
timeInterval: null, timeInterval: null,