Introduction of corresponding components in the language pack main.js
eg:
. 1 Import VueI18n from 'the i18n-VUE'; // introducing internationalized 2 Import from elementen 'UI-Element / lib / the locale / lang / EN'; // Element UI-English language pack . 3 Import elementZh from 'UI-Element / lib / the locale / lang / ZH-the CN '; // Element Chinese-language pack UI . 4 . 5 Import ivewZh from' iView / dist / the locale / ZH-the CN '; // ivew Chinese language pack . 6 Import from ivewEn' iView / dist / locale / EN-US '; // ivew English language pack 7 8 Import from zh' ./i18n/lang/zh '; // own Chinese language pack 9 Import from EN' ./i18n/lang/en ';// own English language pack 10 // This is the main problem lies not changed . 11 Vue.use (the iView, { 12 is the i18n: (Key, value) => I18n.t (Key, value) 13 is }); 14 Vue.use (ElementUI, { 15 the i18n : (Key, value) => I18n.t (Key, value) 16 }); . 17 Vue.use (VueI18n); 18 is . 19 // language international 20 is const messages = { 21 is 'ZH' : { 22 is ... ZH, 23 is ... elementZh, 24 ... ivewZh 25 }, // Chinese language pack 26 is 'EN' : { 27 ...en, 28 ...elementEn, 29 ...ivewEn 30 } //英文语言包 31 }; 32 // 通过cookie存储 33 export function getLanguage() { 34 const chooseLanguage = Cookies.get('language'); 35 if (chooseLanguage) return chooseLanguage; 36 37 const language = (navigator.language || navigator.browserLanguage).toLowerCase(); 38 const locales = Object.keys(messages); 39 for (const locale of locales) { 40 if (language.indexOf(locale) > -1) { 41 return locale; 42 } 43 } 44 return 'en'; 45 } 46 47 const i18n = new VueI18n({ 48 locale: getLanguage(), // 语言标识 49 messages 50 }) 51 52 new Vue({ 53 el: '#app', 54 i18n 55 })