提交 85032a3f 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!521 UI add protecting of language settings

Merge pull request !521 from 黄伟锋/myMaster
...@@ -172,12 +172,14 @@ export default { ...@@ -172,12 +172,14 @@ export default {
set(val) {}, set(val) {},
}, },
isChinese() { isChinese() {
let isChinese = false; let isChinese = true;
if ( const languageList = ['zh-cn', 'en-us'];
localStorage.getItem('milang') && const language = window.localStorage.getItem('milang');
localStorage.getItem('milang') === 'zh-cn'
) { if (language && languageList.includes(language)) {
isChinese = true; isChinese = language === languageList[0];
} else {
window.localStorage.setItem('milang', languageList[0]);
} }
return isChinese; return isChinese;
}, },
......
...@@ -37,14 +37,15 @@ function loadLocaleMessages() { ...@@ -37,14 +37,15 @@ function loadLocaleMessages() {
} }
/* load default language pack */ /* load default language pack */
const languageList = ['zh-cn', 'en-us'];
const langStorge = window.localStorage.getItem('milang'); const langStorge = window.localStorage.getItem('milang');
let langflag; let langflag;
// Check language by default // Check language by default
if (langStorge) { if (langStorge && languageList.includes(langStorge)) {
langflag = langStorge; langflag = langStorge;
} else { } else {
// set Chinese if no default language // set Chinese if no default language
langflag = 'zh-cn'; langflag = languageList[0];
window.localStorage.setItem('milang', langflag); window.localStorage.setItem('milang', langflag);
} }
......
...@@ -26,10 +26,14 @@ import $ from 'jquery'; ...@@ -26,10 +26,14 @@ import $ from 'jquery';
import locale from 'element-ui/lib/locale/lang/en'; import locale from 'element-ui/lib/locale/lang/en';
import localezh from 'element-ui/lib/locale/lang/zh-CN'; import localezh from 'element-ui/lib/locale/lang/zh-CN';
if ( let language = window.localStorage.getItem('milang');
localStorage.getItem('milang') && const languageList = ['zh-cn', 'en-us'];
localStorage.getItem('milang') !== 'zh-cn' if (!language || !languageList.includes(language)) {
) { language = languageList[0];
window.localStorage.setItem('milang', language);
}
if (language !== languageList[0]) {
Vue.use(ElementUI, {locale}); Vue.use(ElementUI, {locale});
} else { } else {
Vue.use(ElementUI, {localezh}); Vue.use(ElementUI, {localezh});
......
...@@ -529,7 +529,14 @@ export default { ...@@ -529,7 +529,14 @@ export default {
} }
this.trainJobID = this.$route.query.train_id; 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( document.title = `${decodeURIComponent(this.trainJobID)}-${this.$t(
'graph.titleText', 'graph.titleText',
)}-MindInsight`; )}-MindInsight`;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册