引入语言包

This commit is contained in:
2026-01-14 12:14:32 +08:00
parent e01690803d
commit 2ce76820da
9 changed files with 406 additions and 21 deletions
+34
View File
@@ -0,0 +1,34 @@
import { defineStore } from 'pinia'
import i18n from '@/i18n'
export const useI18nStore = defineStore('i18n', {
state: () => ({
currentLocale: 'zh-CN',
availableLocales: [
{ label: '简体中文', value: 'zh-CN' },
{ label: 'English', value: 'en-US' }
]
}),
getters: {
localeLabel: (state) => {
const locale = state.availableLocales.find((item) => item.value === state.currentLocale)
return locale ? locale.label : ''
}
},
actions: {
setLocale(locale) {
this.currentLocale = locale
i18n.global.locale.value = locale
localStorage.setItem('locale', locale)
},
initLocale() {
const savedLocale = localStorage.getItem('locale')
if (savedLocale && this.availableLocales.some((item) => item.value === savedLocale)) {
this.setLocale(savedLocale)
}
}
}
})