-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (32 loc) · 787 Bytes
/
index.js
File metadata and controls
40 lines (32 loc) · 787 Bytes
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
36
37
38
39
40
import { createI18n } from 'vue-i18n'
import customEnUS from './en_US'
import customZhCN from './zh_CN'
const ENUM_LANG = {
enUS: 'en_US',
zhCN: 'zh_CN'
}
export const i18n = createI18n({
legacy: false,
locale: ENUM_LANG.zhCN,
messages: {
[ENUM_LANG.enUS]: {
...customEnUS,
},
[ENUM_LANG.zhCN]: {
...customZhCN,
}
}
})
export const setLang = (lang) => {
i18n.global.locale.value = lang
}
export const getLang = () => {
return i18n && i18n.global.locale.value
}
// 获取UA语言类型
export const getUAgentLang = () => {
const UA = window.navigator.userAgent
const regx = new RegExp(`LANG/(${ENUM_LANG.enUS}|${ENUM_LANG.zhHK}|${ENUM_LANG.zhCN})`, 'g')
const result = regx.exec(UA)
return result ? result[1] : ENUM_LANG.zhCN
}