Improve example lang. (#990)

pull/1001/head
FuryBean 2016-11-11 16:58:44 +08:00 committed by cinwell.li
parent 63d68f8f0e
commit b215f71d2e
2 changed files with 9 additions and 2 deletions

View File

@ -200,6 +200,7 @@
methods: { methods: {
switchLang(targetLang) { switchLang(targetLang) {
if (this.lang === targetLang) return; if (this.lang === targetLang) return;
localStorage.setItem('ELEMENT_LANGUAGE', targetLang);
this.$router.push(this.$route.path.replace(this.lang, targetLang)); this.$router.push(this.$route.path.replace(this.lang, targetLang));
} }
}, },

View File

@ -85,12 +85,18 @@ langs.forEach(lang => {
route = route.concat(generateMiscRoutes(lang.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([{ route = route.concat([{
path: '/', path: '/',
redirect: '/zh-CN' redirect: defaultPath
}, { }, {
path: '*', path: '*',
redirect: '/zh-CN' redirect: defaultPath
}]); }]);
export default route; export default route;