diff --git a/mindinsight/ui/src/components/header.vue b/mindinsight/ui/src/components/header.vue index 647e7e0d42f031b97e20bae6a0d136ede6d66260..0b1b41e3a06aceb3bc657436329243113d7c032b 100644 --- a/mindinsight/ui/src/components/header.vue +++ b/mindinsight/ui/src/components/header.vue @@ -172,12 +172,14 @@ export default { set(val) {}, }, isChinese() { - let isChinese = false; - if ( - localStorage.getItem('milang') && - localStorage.getItem('milang') === 'zh-cn' - ) { - isChinese = true; + let isChinese = true; + const languageList = ['zh-cn', 'en-us']; + const language = window.localStorage.getItem('milang'); + + if (language && languageList.includes(language)) { + isChinese = language === languageList[0]; + } else { + window.localStorage.setItem('milang', languageList[0]); } return isChinese; }, diff --git a/mindinsight/ui/src/i18n.js b/mindinsight/ui/src/i18n.js index b8f4d4608ac67d913653c5d87040cd703cd55c64..79b7e4e08b2bf863d719776990f7f3a0848acaa9 100644 --- a/mindinsight/ui/src/i18n.js +++ b/mindinsight/ui/src/i18n.js @@ -37,14 +37,15 @@ function loadLocaleMessages() { } /* load default language pack */ +const languageList = ['zh-cn', 'en-us']; const langStorge = window.localStorage.getItem('milang'); let langflag; // Check language by default -if (langStorge) { +if (langStorge && languageList.includes(langStorge)) { langflag = langStorge; } else { // set Chinese if no default language - langflag = 'zh-cn'; + langflag = languageList[0]; window.localStorage.setItem('milang', langflag); } diff --git a/mindinsight/ui/src/main.js b/mindinsight/ui/src/main.js index 121b8c2c942eee33fdbcbf1a72e9671eec32b237..93804c801657d55c25ec5cfc09c0b376a7333ded 100644 --- a/mindinsight/ui/src/main.js +++ b/mindinsight/ui/src/main.js @@ -26,10 +26,14 @@ import $ from 'jquery'; import locale from 'element-ui/lib/locale/lang/en'; import localezh from 'element-ui/lib/locale/lang/zh-CN'; -if ( - localStorage.getItem('milang') && - localStorage.getItem('milang') !== 'zh-cn' -) { +let language = window.localStorage.getItem('milang'); +const languageList = ['zh-cn', 'en-us']; +if (!language || !languageList.includes(language)) { + language = languageList[0]; + window.localStorage.setItem('milang', language); +} + +if (language !== languageList[0]) { Vue.use(ElementUI, {locale}); } else { Vue.use(ElementUI, {localezh}); diff --git a/mindinsight/ui/src/views/train-manage/graph.vue b/mindinsight/ui/src/views/train-manage/graph.vue index 904a02ffea2386652ed433cc7ee3255612eb092b..25fc7ae8e9b600a60e8a60d3978b906fc028eab5 100644 --- a/mindinsight/ui/src/views/train-manage/graph.vue +++ b/mindinsight/ui/src/views/train-manage/graph.vue @@ -529,7 +529,14 @@ export default { } this.trainJobID = this.$route.query.train_id; - this.language = localStorage.getItem('milang') || 'zh-cn'; + + this.language = window.localStorage.getItem('milang'); + const languageList = ['zh-cn', 'en-us']; + if (!this.language || !languageList.includes(this.language)) { + this.language = languageList[0]; + window.localStorage.setItem('milang', this.language); + } + document.title = `${decodeURIComponent(this.trainJobID)}-${this.$t( 'graph.titleText', )}-MindInsight`;