feat(I18n): Add Ii8n
feat(LocaleDropdown): Add LocaleDropdown Component feat(store): Add localeStore
This commit is contained in:
3
src/plugins/i18n/helper.ts
Normal file
3
src/plugins/i18n/helper.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export function setHtmlPageLang(locale: LocaleType) {
|
||||
document.querySelector('html')?.setAttribute('lang', locale)
|
||||
}
|
||||
@@ -1,16 +1,42 @@
|
||||
import type { App } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import { useLocaleStoreWithOut } from '@/store/modules/locale'
|
||||
import type { I18n, I18nOptions } from 'vue-i18n'
|
||||
import { setHtmlPageLang } from './helper'
|
||||
|
||||
export const i18n = setupI18n()
|
||||
export let i18n: ReturnType<typeof createI18n>
|
||||
|
||||
function setupI18n() {
|
||||
const messages = Object.fromEntries(
|
||||
Object.entries(import.meta.globEager('../../locales/*.ts')).map(([key, value]) => {
|
||||
return [key.slice(14, -3), value.default]
|
||||
})
|
||||
)
|
||||
return createI18n({
|
||||
legacy: false,
|
||||
locale: 'zh-CN',
|
||||
messages
|
||||
async function createI18nOptions(): Promise<I18nOptions> {
|
||||
const localeStore = useLocaleStoreWithOut()
|
||||
const locale = localeStore.getLocale
|
||||
const localeMap = localeStore.getLocaleMap
|
||||
const defaultLocal = await import(`../../locales/${locale.lang}.ts`)
|
||||
const message = defaultLocal.default ?? {}
|
||||
|
||||
setHtmlPageLang(locale.lang)
|
||||
|
||||
localeStore.setLocale({
|
||||
lang: locale.lang
|
||||
// elLocale: elLocal
|
||||
})
|
||||
|
||||
return {
|
||||
legacy: false,
|
||||
locale: locale.lang,
|
||||
fallbackLocale: locale.lang,
|
||||
messages: {
|
||||
[locale.lang]: message
|
||||
},
|
||||
availableLocales: localeMap.map((v) => v.lang),
|
||||
sync: true,
|
||||
silentTranslationWarn: true,
|
||||
missingWarn: false,
|
||||
silentFallbackWarn: true
|
||||
}
|
||||
}
|
||||
|
||||
export async function setupI18n(app: App) {
|
||||
const options = await createI18nOptions()
|
||||
i18n = createI18n(options) as I18n
|
||||
app.use(i18n)
|
||||
}
|
||||
|
||||
3
src/plugins/svgIcon/index.ts
Normal file
3
src/plugins/svgIcon/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import 'virtual:svg-icons-register'
|
||||
|
||||
import '@purge-icons/generated'
|
||||
Reference in New Issue
Block a user