| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import Vue from "vue"
- import VueI18n from "vue-i18n"
- import api from '../api/api';
- import ElementLocale from 'element-ui/lib/locale'
- import enLocale from 'element-ui/lib/locale/lang/en'
- import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
- import ruLocale from 'element-ui/lib/locale/lang/ru-RU'
- ElementLocale.i18n((key, value) => i18n.t(key, value)) //为了实现element插件的多语言切换
- Vue.use(VueI18n); // 全局注册国际化包
- let languages = localStorage.getItem('languages') ? JSON.parse(localStorage.getItem('languages')) : {
- RU: {},
- EN: {}
- },
- messages = {
- 'ZH': {
- ...zhLocale
- },
- 'EN': {
- ...enLocale,
- ...languages.EN
- },
- 'RU': {
- ...ruLocale,
- ...languages.RU
- }
- };
- api.requested({
- id: 2024062809072801,
- }).then(res => {
- if (res.code != 1) return;
- languages = res.data;
- localStorage.setItem('languages', JSON.stringify(languages))
- })
- console.log("locale", localStorage.getItem('lang') )
- // 准备翻译的语言环境信息
- const i18n = new VueI18n({
- locale: localStorage.getItem('lang') || "ZH", //将语言标识存入localStorage或sessionStorage中,页面刷新不会默认中文显示
- messages,
- silentTranslationWarn: true, //解决vue-i18n黄色警告"value of key 'xxx' is not a string"和"cannot translate the value of keypath 'xxx'.use the value of keypath as default",可忽略
- globalInjection: true, // 全局注入
- fallbackLocale: 'ZH', // 指定的locale没有找到对应的资源或当前语种不存在时,默认设置当前语种为中文
- });
- export default i18n
|