* feat: i18n * chore: format * feat: 补充遗漏翻译 * chore: update deps * feat: 复制代码块[#196][#197] * chore: version 2.9.1
35 lines
708 B
TypeScript
35 lines
708 B
TypeScript
import type { App } from 'vue'
|
|
import { createI18n } from 'vue-i18n'
|
|
import en from './en-US'
|
|
import cn from './zh-CN'
|
|
import { useAppStoreWithOut } from '@/store/modules/app'
|
|
import type { Language } from '@/store/modules/app/helper'
|
|
|
|
const appStore = useAppStoreWithOut()
|
|
|
|
const defaultLocale = appStore.language || 'zh-CN'
|
|
|
|
const i18n = createI18n({
|
|
locale: defaultLocale,
|
|
fallbackLocale: 'en-US',
|
|
allowComposition: true,
|
|
messages: {
|
|
'en-US': en,
|
|
'zh-CN': cn,
|
|
},
|
|
})
|
|
|
|
export function t(key: string) {
|
|
return i18n.global.t(key)
|
|
}
|
|
|
|
export function setLocale(locale: Language) {
|
|
i18n.global.locale = locale
|
|
}
|
|
|
|
export function setupI18n(app: App) {
|
|
app.use(i18n)
|
|
}
|
|
|
|
export default i18n
|