From cf172f5cbc5f9b7f55d72b4da7ebc98d05c06498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= Date: Mon, 9 Dec 2019 16:24:25 +0800 Subject: [PATCH] feat(cli): support switch lang --- docs/site/mobile.js | 4 ++- packages/vant-cli/site/desktop/App.vue | 25 ++++++++++++++--- .../site/desktop/components/Header.vue | 27 ++++++++++++++----- .../site/desktop/components/Simulator.vue | 9 ++++++- .../site/desktop/components/index.vue | 18 ++++--------- .../site/mobile/components/DemoHome.vue | 2 +- vant.config.js | 2 ++ 7 files changed, 61 insertions(+), 26 deletions(-) diff --git a/docs/site/mobile.js b/docs/site/mobile.js index 24d3ce8e2..4b745f262 100644 --- a/docs/site/mobile.js +++ b/docs/site/mobile.js @@ -8,8 +8,9 @@ Vue.mixin({ computed: { $t() { const { name } = this.$options; + const { lang } = this.$route.meta || {}; const prefix = name ? camelize(name) + '.' : ''; - const messages = this.$vantMessages[this.$vantLang]; + const messages = this.$vantMessages[lang]; return (path, ...args) => { const message = get(messages, prefix + path) || get(messages, path); @@ -20,6 +21,7 @@ Vue.mixin({ beforeCreate() { const { i18n, name } = this.$options; + if (i18n) { const locales = {}; const camelizedName = camelize(name); diff --git a/packages/vant-cli/site/desktop/App.vue b/packages/vant-cli/site/desktop/App.vue index 6240cb6ac..d27640470 100644 --- a/packages/vant-cli/site/desktop/App.vue +++ b/packages/vant-cli/site/desktop/App.vue @@ -1,6 +1,11 @@ @@ -43,16 +38,13 @@ export default { props: { lang: String, versions: Array, - currentSimulator: Number, simulator: String, + langConfigs: Array, + currentSimulator: Number, config: { type: Object, required: true }, - simulators: { - type: Array, - default: () => [] - }, base: { type: String, default: '' diff --git a/packages/vant-cli/site/mobile/components/DemoHome.vue b/packages/vant-cli/site/mobile/components/DemoHome.vue index 28b99d147..3177d2764 100644 --- a/packages/vant-cli/site/mobile/components/DemoHome.vue +++ b/packages/vant-cli/site/mobile/components/DemoHome.vue @@ -26,7 +26,7 @@ export default { computed: { lang() { - const { lang } = this.$route.meta || {}; + const { lang } = this.$route.meta; return lang; }, diff --git a/vant.config.js b/vant.config.js index 672e0c75d..99b5b5d26 100644 --- a/vant.config.js +++ b/vant.config.js @@ -12,6 +12,7 @@ module.exports = { title: 'Vant', description: '轻量、可靠的移动端 Vue 组件库', logo: 'https://img.yzcdn.cn/vant/logo.png', + langLabel: '中文', links: [ { logo: 'https://b.yzcdn.cn/vant/logo/weapp.svg', @@ -355,6 +356,7 @@ module.exports = { title: 'Vant', description: 'Mobile UI Components built on Vue', logo: 'https://img.yzcdn.cn/vant/logo.png', + langLabel: 'En', links: [ { logo: 'https://b.yzcdn.cn/vant/logo/weapp.svg',