feat: i18n lazy load
This commit is contained in:
parent
ccffe9daa8
commit
07209a7d29
6 changed files with 25 additions and 17 deletions
|
@ -1,10 +1,11 @@
|
|||
import { APP_NAME } from '~/constants'
|
||||
import { APP_NAME, STORAGE_KEY_LANG } from '~/constants'
|
||||
|
||||
const isDev = process.dev
|
||||
const isPreview = window.location.hostname.includes('deploy-preview')
|
||||
|
||||
export function usePageHeader() {
|
||||
export function setupPageHeader() {
|
||||
const i18n = useI18n()
|
||||
|
||||
useHeadFixed({
|
||||
htmlAttrs: {
|
||||
lang: () => i18n.locale.value,
|
||||
|
@ -21,3 +22,17 @@ export function usePageHeader() {
|
|||
// eslint-disable-next-line no-unused-expressions
|
||||
isDark.value
|
||||
}
|
||||
|
||||
export async function setupI18n() {
|
||||
// TODO: guess user language
|
||||
|
||||
const { locale, setLocale } = useI18n()
|
||||
const localeStorage = useLocalStorage(STORAGE_KEY_LANG, locale.value)
|
||||
|
||||
if (localeStorage.value !== locale.value)
|
||||
await setLocale(localeStorage.value)
|
||||
|
||||
watchEffect(() => {
|
||||
localeStorage.value = locale.value
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue