t20-common-lib 0.9.4 → 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,69 @@
1
+ import locale from 'element-ui/lib/locale'
2
+ import langEn from 'element-ui/lib/locale/lang/en'
3
+ import langTh from 'element-ui/lib/locale/lang/th'
4
+ import langVi from 'element-ui/lib/locale/lang/vi'
5
+ import langTw from 'element-ui/lib/locale/lang/zh-TW'
6
+
7
+ import i18n_map_local from '../../i18n.json'
8
+ import zhHk from './cn2hk.json' // 简体繁体映射
9
+ // 语言枚举
10
+ // const langEm = { 中文: 'zh', 中文简体: 'zh-cn', 中文繁体: 'zh-hk', 英文: 'en', 德文: 'de', 法文: 'fr' }
11
+
12
+ let pageLang = window.localStorage.getItem('pageLang') // 当前页面的语言
13
+ let $i18n_map_root = {} // 全局的国际化
14
+
15
+ export function $l(zh, map = {}, arg) {
16
+ let val = ''
17
+ if (!pageLang || pageLang === 'zh-cn') {
18
+ val = zh
19
+ } else if (pageLang === 'zh-hk') {
20
+ val = cn2hk(zh)
21
+ } else {
22
+ let key = pageLang
23
+ let valMap = map[zh] || $i18n_map_root[zh] || {}
24
+ val = valMap[key] !== undefined ? valMap[key] : zh
25
+ }
26
+ if (arg && val) {
27
+ for (let k in arg) {
28
+ val = val.replace(k, arg[k])
29
+ }
30
+ }
31
+ return val
32
+ }
33
+ function cn2hk(zh = '') {
34
+ let _zh = ''
35
+ for (let i = 0; i < zh.length; i++) {
36
+ let v = zh[i]
37
+ let v_hk = zhHk[v]
38
+ v_hk ? (_zh += v_hk) : (_zh += v)
39
+ }
40
+ return _zh
41
+ }
42
+
43
+ export function $lc(zh, map) {
44
+ return $l(zh, map || i18n_map_local)
45
+ }
46
+
47
+ const directive = {}
48
+ directive.install = (Vue, map = {}) => {
49
+ if (pageLang === 'en') {
50
+ locale.use(langEn)
51
+ } else if (pageLang === 'zh-hk') {
52
+ locale.use(langTw)
53
+ } else if (pageLang === 'th') {
54
+ locale.use(langTh)
55
+ } else if (pageLang === 'vi') {
56
+ locale.use(langVi)
57
+ }
58
+
59
+ $i18n_map_root = map
60
+
61
+ Vue.prototype._lang = !pageLang || pageLang === 'zh-cn' || pageLang === 'zh-hk' ? 'zh' : pageLang
62
+ Vue.prototype.$l = $l
63
+ Vue.filter('$l', $l)
64
+
65
+ Vue.prototype.$lc = $lc
66
+ Vue.filter('$lc', $lc)
67
+ }
68
+
69
+ export default directive