fix(i18n): language switch is reset (#215)

Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
This commit is contained in:
kazuya kawaguchi 2022-11-29 15:29:09 +09:00 committed by GitHub
parent 08fe00df6d
commit 22e90b5ffd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 9 deletions

View file

@ -1,12 +1,15 @@
<script lang="ts" setup>
import type { LocaleObject } from '@nuxtjs/i18n/dist/runtime/composables'
import type { ComputedRef } from 'vue'
import type { LocaleObject } from '#i18n'
import { STORAGE_KEY_LANG } from '~/constants'
const { locale, t } = useI18n()
const { locale, t, setLocale } = useI18n()
const { locales } = useI18n() as { locales: ComputedRef<LocaleObject[]> }
useLocalStorage(STORAGE_KEY_LANG, locale)
const { locales } = useI18n() as { locales: ComputedRef<LocaleObject[]> }
const handleLocale = async (locale: string) => {
await setLocale(locale)
}
</script>
<template>
@ -21,7 +24,7 @@ const { locales } = useI18n() as { locales: ComputedRef<LocaleObject[]> }
v-for="item in locales"
:key="item.code"
:checked="item.code === locale"
@click="locale = item.code"
@click="handleLocale(item.code)"
>
{{ item.name }}
</CommonDropdownItem>

View file

@ -22,7 +22,7 @@
"@iconify-json/logos": "^1.1.19",
"@iconify-json/ri": "^1.1.4",
"@iconify-json/twemoji": "^1.1.6",
"@nuxtjs/i18n": "8.0.0-beta.5",
"@nuxtjs/i18n": "^8.0.0-beta.6",
"@pinia/nuxt": "^0.4.5",
"@tiptap/extension-character-count": "2.0.0-beta.204",
"@tiptap/extension-code-block": "2.0.0-beta.204",

View file

@ -7,7 +7,7 @@ specifiers:
'@iconify-json/logos': ^1.1.19
'@iconify-json/ri': ^1.1.4
'@iconify-json/twemoji': ^1.1.6
'@nuxtjs/i18n': 8.0.0-beta.5
'@nuxtjs/i18n': ^8.0.0-beta.6
'@pinia/nuxt': ^0.4.5
'@tiptap/extension-character-count': 2.0.0-beta.204
'@tiptap/extension-code-block': 2.0.0-beta.204
@ -65,7 +65,7 @@ devDependencies:
'@iconify-json/logos': 1.1.19
'@iconify-json/ri': 1.1.4
'@iconify-json/twemoji': 1.1.6
'@nuxtjs/i18n': 8.0.0-beta.5
'@nuxtjs/i18n': 8.0.0-beta.6
'@pinia/nuxt': 0.4.5_typescript@4.9.3
'@tiptap/extension-character-count': 2.0.0-beta.204
'@tiptap/extension-code-block': 2.0.0-beta.204
@ -1072,8 +1072,8 @@ packages:
- vti
dev: true
/@nuxtjs/i18n/8.0.0-beta.5:
resolution: {integrity: sha512-UGyo80GDd8eYLCYPc+/XKPOQ0MUy7OLbSp5Zud95no6E9yAFxDNrgjaolTKV/f7U/QhSF0+xUOUC32TE8uj5Pg==}
/@nuxtjs/i18n/8.0.0-beta.6:
resolution: {integrity: sha512-aZJ1cYmRR/r92O33PTmL8czMq2lBMliyPFzLCOB5BA3oFKY0WafTAPxi8f/VYtlWf+8JT22oZ2UeZRhpxdFPuw==}
engines: {node: ^14.16.0 || ^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0}
dependencies:
'@intlify/bundle-utils': 3.4.0_vue-i18n@9.3.0-beta.10