1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  | import Vue from "vue" 
 |  import VueI18n from "vue-i18n" 
 |    
 |  // 导入本地国际化文件 
 |  import enLocal from "./en-US" 
 |  import zhLocal from "./zh-CN" 
 |    
 |  const messages = { 
 |    "en-US": { 
 |      ...enLocal 
 |    }, 
 |    "zh-CN": { 
 |      ...zhLocal 
 |    } 
 |  } 
 |  Vue.use(VueI18n) 
 |  const i18n = new VueI18n({ 
 |    locale: "zh-CN", 
 |    messages 
 |  }) 
 |    
 |  function t(key, ...args) { 
 |    if (args.length === 0) { 
 |      return i18n.t(key) 
 |    } else if (args.length === 1 && (typeof args[0]).toLowerCase() === "string") { 
 |      return i18n.t(key, { field: i18n.t(args[0]) }) 
 |    } else if (args.length === 1 && (typeof args[0]).toLowerCase() === "object") { 
 |      let obj = {} 
 |      return i18n.t(key, obj) 
 |    } else { 
 |      throw new Error("出错了,请联系管理员") 
 |    } 
 |  } 
 |    
 |  export { i18n as default, t } 
 |  
  |