Files
vueadmin/src/stores/modules/i18n.js
T
2026-01-25 14:09:47 +08:00

35 lines
656 B
JavaScript

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
}
},
persist: {
key: 'i18n-store',
pick: ['currentLocale']
}
}
)