i18n.js
1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import Vue from 'vue'
import locale from 'element-ui/lib/locale'
import VueI18n from 'vue-i18n'
import axios from 'axios';
import $ from 'jquery';
/*******************************/
import cnLocale from 'element-ui/lib/locale/lang/zh-CN';
import usLocale from 'element-ui/lib/locale/lang/en';
import twLocale from 'element-ui/lib/locale/lang/zh-TW'
const uiLocale = {
cn: cnLocale,
us: usLocale,
tw: twLocale
};
/*******************************/
Vue.use(VueI18n)
const i18n = new VueI18n({
})
var lang = ['zh_CN', 'en_US', 'zh_TW'];
function loadI18nMessages(lang) {
let langUrl;
let languageUrl = window._vionConfig.languageUrl;
if (languageUrl && languageUrl == 'store') {
langUrl = `https://store.keliuyun.com/report/i18n/get/${lang}.json`;
} else if (languageUrl && languageUrl == 'mall') {
langUrl = `https://mall.keliuyun.com/report/i18n/get/${lang}.json`;
} else if (languageUrl && languageUrl == 'static') {
langUrl = `static/langs/${lang}.json`;
} else {
langUrl = `${window._vionConfig.apiUrl}/i18n/get/${lang}.json`;
}
return new Promise((resolve, reject) => {
$.getJSON(langUrl, function(msg) {
let local = lang.split('_')[1].toLowerCase();
let msgObj = Object.assign({}, msg, uiLocale[local]);
i18n.setLocaleMessage(lang, msgObj)
i18n.locale = localStorage.getItem('lang') || 'zh_CN'
resolve()
})
})
}
lang.forEach((item, index) => {
loadI18nMessages(item).then(() => {
if (item == 'zh_CN') {
locale.i18n((key, value) => i18n.t(key, value))
}
})
})
export default i18n