element-ui 中英文切換

import VueI18n from 'vue-i18n'
import ElementUI  from 'element-ui'
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 Cookies from 'js-cookie'
import lang from '@/common/lang' // 中英文翻譯
 
 
 
Vue.use(ElementUI);
Vue.use(VueI18n);
 
const i18n = new VueI18n({
  locale: Cookies.get('language') || 'en', // 語言標識
  messages: {
    en: {
      ...lang.en,
      ...enLocale
    },
    zh: {
      ...lang.zh,
      ...zhLocale
    }
  }
});
 
Cookies.set('language',i18n.locale);
 
ElementLocale.i18n((key, value) => i18n.t(key, value))

原文:https://blog.csdn.net/github_37793365/article/details/83865237

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章