import Vue from 'vue'; import VueI18n from 'vue-i18n'; import { GetWordPack } from '@/api/app'; import ElementLocale from 'element-ui/lib/locale'; import zhLocal from 'element-ui/lib/locale/lang/zh-CN'; import arLocal from 'element-ui/lib/locale/lang/ar'; import enLocal from 'element-ui/lib/locale/lang/en'; import jaLocal from 'element-ui/lib/locale/lang/ja'; import deLocal from 'element-ui/lib/locale/lang/de'; import ruLocal from 'element-ui/lib/locale/lang/ru-RU'; Vue.use(VueI18n); // function getBasicI18nMessage() { // let lang = getI18nLang(); // GetWordPack({ // language_type: lang, // word_key_list: {} // }); // } const i18n = new VueI18n({ locale: localStorage.getItem('lang') || 'ZH', messages: { ZH: { ...zhLocal }, AR: { ...arLocal }, EN: { ...enLocal }, JA: { ...jaLocal }, DE: { ...deLocal }, RU: { ...ruLocal } }, silentTranslationWarn: true }); ElementLocale.i18n((key, value) => i18n.t(key, value)); export function setI18nLang(lang) { localStorage.setItem('lang', lang); i18n.locale = lang; } /** * @description 更新语言列表 * @param {Object} Parameter word_key_list 需要读取的词汇 */ export function updateWordPack(Parameter) { Parameter.language_type = i18n.locale; GetWordPack(Parameter).then(data => { let localWord = i18n.messages[data.language_type]; if (localWord === undefined) { localWord = {}; } let wordPack = Object.assign(localWord, data.word_pack); i18n.setLocaleMessage(data.language_type, wordPack); }); } export default i18n;