index.js
1.2 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
import { createI18n } from 'vue-i18n'
import store from '@/store'
import useAppStore from '@/store/modules/app'
// 本地语言包
import enLocale from './package/en'
import zhCnLocale from './package/zh-cn'
import ruLocale from './package/ru'
const appStore = useAppStore(store);
function siphonI18n(prefix = 'zh-CN') {
return Object.fromEntries(
Object.entries(import.meta.glob('./**/*.ts', { eager: true })).map(([key, value]) => {
const matched = key.match(/([A-Za-z0-9-_]+)\./i)[1]
return [matched, value.default]
})
)[prefix]
}
const messages = {
'zh_CN': {
...zhCnLocale,
...siphonI18n('zh-cn')
},
'en_US': {
...enLocale,
...siphonI18n('en')
},
'ru_RU': {
...ruLocale,
...siphonI18n('ru')
}
}
// console.log(appStore)
const i18n = createI18n({
legacy: false, // 如果想在composition api中使用需要设置为false
locale: appStore.language,
// TODO: Type instantiation is excessively deep and possibly infinite. https://github.com/intlify/vue-i18n-next/issues/1119
messages: messages,
globalInjection: true // 如果设置true, $t() 函数将注册到全局
})
export default i18n
// import i18n from '@/lang/index'
// const { t } = i18n.global