From b215f71d2ed71e05650cd35720fff6430933845e Mon Sep 17 00:00:00 2001 From: FuryBean Date: Fri, 11 Nov 2016 16:58:44 +0800 Subject: [PATCH] Improve example lang. (#990) --- examples/components/header.vue | 1 + examples/route.config.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/components/header.vue b/examples/components/header.vue index 67276792e..75877a788 100644 --- a/examples/components/header.vue +++ b/examples/components/header.vue @@ -200,6 +200,7 @@ methods: { switchLang(targetLang) { if (this.lang === targetLang) return; + localStorage.setItem('ELEMENT_LANGUAGE', targetLang); this.$router.push(this.$route.path.replace(this.lang, targetLang)); } }, diff --git a/examples/route.config.js b/examples/route.config.js index 75793c01d..a93610929 100644 --- a/examples/route.config.js +++ b/examples/route.config.js @@ -85,12 +85,18 @@ langs.forEach(lang => { route = route.concat(generateMiscRoutes(lang.lang)); }); +let userLanguage = localStorage.getItem('ELEMENT_LANGUAGE') || window.navigator.language; +let defaultPath = '/en-US'; +if (userLanguage.indexOf('zh-') !== -1) { + defaultPath = '/zh-CN'; +} + route = route.concat([{ path: '/', - redirect: '/zh-CN' + redirect: defaultPath }, { path: '*', - redirect: '/zh-CN' + redirect: defaultPath }]); export default route;