Update i18n

This commit is contained in:
mizhexiaoxiao 2024-02-02 11:06:07 +08:00
parent 9b12fe6355
commit 7634167ed5
5 changed files with 16 additions and 13 deletions

View File

@ -1,15 +1,15 @@
import { createI18n } from 'vue-i18n' import { createI18n } from 'vue-i18n'
import { sStorage } from '@/utils' import { lStorage } from '@/utils'
import messages from './messages' import messages from './messages'
const currentLocale = sStorage.get('locale') const currentLocale = lStorage.get('locale')
const i18n = createI18n({ const i18n = createI18n({
legacy: false, legacy: false,
globalInjection: true, globalInjection: true,
locale: currentLocale || 'en', locale: currentLocale || 'cn',
fallbackLocale: 'en', fallbackLocale: 'cn',
messages: messages, messages: messages,
}) })

View File

@ -9,6 +9,7 @@
<script setup> <script setup>
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { useAppStore } from '@/store' import { useAppStore } from '@/store'
import { router } from '~/src/router'
const store = useAppStore() const store = useAppStore()
const { availableLocales, t } = useI18n() const { availableLocales, t } = useI18n()
@ -26,5 +27,7 @@ const options = computed(() => {
const handleChangeLocale = (value) => { const handleChangeLocale = (value) => {
store.setLocale(value) store.setLocale(value)
// reload page
router.go()
} }
</script> </script>

View File

@ -1,9 +1,9 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { useDark } from '@vueuse/core' import { useDark } from '@vueuse/core'
import { sStorage } from '@/utils' import { lStorage } from '@/utils'
import i18n from '~/i18n' import i18n from '~/i18n'
const currentLocale = sStorage.get('locale') const currentLocale = lStorage.get('locale')
const { locale } = i18n.global const { locale } = i18n.global
const isDark = useDark() const isDark = useDark()
@ -54,7 +54,7 @@ export const useAppStore = defineStore('app', {
setLocale(newLocale) { setLocale(newLocale) {
this.locale = newLocale this.locale = newLocale
locale.value = newLocale locale.value = newLocale
sStorage.set('locale', newLocale) lStorage.set('locale', newLocale)
}, },
}, },
}) })

View File

@ -1,6 +1,6 @@
import { sStorage } from '@/utils' import { lStorage } from '@/utils'
export const activeTag = sStorage.get('activeTag') export const activeTag = lStorage.get('activeTag')
export const tags = sStorage.get('tags') export const tags = lStorage.get('tags')
export const WITHOUT_TAG_PATHS = ['/404', '/login'] export const WITHOUT_TAG_PATHS = ['/404', '/login']

View File

@ -1,7 +1,7 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { activeTag, tags, WITHOUT_TAG_PATHS } from './helpers' import { activeTag, tags, WITHOUT_TAG_PATHS } from './helpers'
import { router } from '@/router' import { router } from '@/router'
import { sStorage } from '@/utils' import { lStorage } from '@/utils'
export const useTagsStore = defineStore('tag', { export const useTagsStore = defineStore('tag', {
state() { state() {
@ -18,11 +18,11 @@ export const useTagsStore = defineStore('tag', {
actions: { actions: {
setActiveTag(path) { setActiveTag(path) {
this.activeTag = path this.activeTag = path
sStorage.set('activeTag', path) lStorage.set('activeTag', path)
}, },
setTags(tags) { setTags(tags) {
this.tags = tags this.tags = tags
sStorage.set('tags', tags) lStorage.set('tags', tags)
}, },
addTag(tag = {}) { addTag(tag = {}) {
this.setActiveTag(tag.path) this.setActiveTag(tag.path)