Add File
This commit is contained in:
35
frontend/src/i18n/index.ts
Normal file
35
frontend/src/i18n/index.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import en from './en.json'
|
||||
import zhCN from './zh-CN.json'
|
||||
import elementEnLocale from 'element-plus-secondary/es/locale/lang/en'
|
||||
import elementZhLocale from 'element-plus-secondary/es/locale/lang/zh-cn'
|
||||
import { useCache } from '@/utils/useCache'
|
||||
const { wsCache } = useCache()
|
||||
|
||||
const getDefaultLocale = () => {
|
||||
const language = wsCache.get('user.language')
|
||||
return language || 'zh-CN'
|
||||
}
|
||||
|
||||
const messages = {
|
||||
en: {
|
||||
...en,
|
||||
el: elementEnLocale,
|
||||
},
|
||||
'zh-CN': {
|
||||
...zhCN,
|
||||
el: elementZhLocale,
|
||||
},
|
||||
}
|
||||
|
||||
export const i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: getDefaultLocale(),
|
||||
fallbackLocale: 'en',
|
||||
globalInjection: true,
|
||||
messages,
|
||||
})
|
||||
|
||||
export const getElementLocale = () => {
|
||||
return i18n.global.locale.value === 'en' ? elementEnLocale : elementZhLocale
|
||||
}
|
||||
Reference in New Issue
Block a user