-
Notifications
You must be signed in to change notification settings - Fork 689
Expand file tree
/
Copy pathindex.ts
More file actions
56 lines (50 loc) · 1.32 KB
/
index.ts
File metadata and controls
56 lines (50 loc) · 1.32 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { createI18n } from 'vue-i18n'
import en from './en.json'
import zhCN from './zh-CN.json'
import zhTw from './zh-TW.json'
import koKR from './ko-KR.json'
import elementEnLocale from 'element-plus-secondary/es/locale/lang/en'
import elementZhLocale from 'element-plus-secondary/es/locale/lang/zh-cn'
import elementTwLocale from 'element-plus-secondary/es/locale/lang/zh-tw'
import { useCache } from '@/utils/useCache'
import { getBrowserLocale } from '@/utils/utils'
const elementKoLocale = elementEnLocale
const { wsCache } = useCache()
const getDefaultLocale = () => {
return wsCache.get('user.language') || getBrowserLocale() || 'zh-CN'
}
const messages = {
en: {
...en,
el: elementEnLocale,
},
'zh-CN': {
...zhCN,
el: elementZhLocale,
},
'zh-TW': {
...zhTw,
el: elementTwLocale,
},
'ko-KR': {
...koKR,
el: elementKoLocale,
},
}
export const i18n = createI18n({
legacy: false,
locale: getDefaultLocale(),
fallbackLocale: 'zh-CN',
globalInjection: true,
messages,
})
const elementLocales = {
en: elementEnLocale,
'zh-CN': elementZhLocale,
'zh-TW': elementTwLocale,
'ko-KR': elementKoLocale,
} as const
export const getElementLocale = () => {
const locale = i18n.global.locale.value as keyof typeof elementLocales
return elementLocales[locale] ?? elementEnLocale
}