i18n.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import Vue from 'vue';
  2. import VueI18n from 'vue-i18n';
  3. import store from '../store';
  4. import { getStaticContent } from '@/api/api';
  5. import ElementLocale from 'element-ui/lib/locale';
  6. import zhLocal from 'element-ui/lib/locale/lang/zh-CN';
  7. import arLocal from 'element-ui/lib/locale/lang/ar';
  8. import enLocal from 'element-ui/lib/locale/lang/en';
  9. import jaLocal from 'element-ui/lib/locale/lang/ja';
  10. import deLocal from 'element-ui/lib/locale/lang/de';
  11. import ruLocal from 'element-ui/lib/locale/lang/ru-RU';
  12. Vue.use(VueI18n);
  13. const i18n = new VueI18n({
  14. locale: localStorage.getItem('language_type') || "ZH", //store.getters.language_type,
  15. messages: {
  16. ZH: {
  17. ...zhLocal
  18. },
  19. AR: {
  20. ...arLocal
  21. },
  22. EN: {
  23. ...enLocal
  24. },
  25. JA: {
  26. ...jaLocal
  27. },
  28. DE: {
  29. ...deLocal
  30. },
  31. RU: {
  32. ...ruLocal
  33. }
  34. },
  35. silentTranslationWarn: true
  36. });
  37. ElementLocale.i18n((key, value) => i18n.t(key, value));
  38. export async function setI18nLang(language_type) {
  39. console.log(language_type);
  40. await store.dispatch('lang/updateLanguageType', language_type);
  41. }
  42. /**
  43. * @description 更新语言列表
  44. * @param {Object} Parameter word_key_list 需要读取的词汇
  45. */
  46. export function updateWordPack(Parameter) {
  47. Parameter.language_type = store.getters.language_type;
  48. let MethodName = 'language_manager-GetWordPack';
  49. getStaticContent(MethodName, Parameter).then(data => {
  50. let localWord = i18n.messages[data.language_type];
  51. if (localWord === undefined) {
  52. localWord = {};
  53. }
  54. let wordPack = Object.assign(localWord, data.word_pack);
  55. i18n.setLocaleMessage(data.language_type, wordPack);
  56. // localStorage.setItem('i18n-message', JSON.stringify(i18n.messages));
  57. });
  58. }
  59. export default i18n;