refactor: migrate to nuxt compatibilityVersion: 4 (#3298)
This commit is contained in:
parent
46e4433e1c
commit
a3fbc056a9
342 changed files with 1200 additions and 2932 deletions
30
app/plugins/setup-i18n.ts
Normal file
30
app/plugins/setup-i18n.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import type { Locale } from '#i18n'
|
||||
|
||||
export default defineNuxtPlugin(async (nuxt) => {
|
||||
const t = nuxt.vueApp.config.globalProperties.$t
|
||||
const d = nuxt.vueApp.config.globalProperties.$d
|
||||
const n = nuxt.vueApp.config.globalProperties.$n
|
||||
|
||||
nuxt.vueApp.config.globalProperties.$t = wrapI18n(t)
|
||||
nuxt.vueApp.config.globalProperties.$d = wrapI18n(d)
|
||||
nuxt.vueApp.config.globalProperties.$n = wrapI18n(n)
|
||||
|
||||
if (import.meta.client) {
|
||||
const i18n = useNuxtApp().$i18n
|
||||
const { setLocale, locales } = i18n
|
||||
const userSettings = useUserSettings()
|
||||
const lang = computed(() => userSettings.value.language as Locale)
|
||||
|
||||
const supportLanguages = unref(locales).map(locale => locale.code)
|
||||
if (!supportLanguages.includes(lang.value))
|
||||
userSettings.value.language = getDefaultLanguage(supportLanguages)
|
||||
|
||||
if (lang.value !== i18n.locale)
|
||||
await setLocale(userSettings.value.language as Locale)
|
||||
|
||||
watch([lang, isHydrated], () => {
|
||||
if (isHydrated.value && lang.value !== i18n.locale)
|
||||
setLocale(lang.value)
|
||||
}, { immediate: true })
|
||||
}
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue