提交 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 {
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;
},
......
......@@ -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);
}
......
......@@ -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});
......
......@@ -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`;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册