import { localeSetting } from '@eciol/shared'; import type { LocaleSetting, LocaleType } from '@eciol/types'; import { defineStore } from 'pinia'; import { context } from '../context'; interface LocaleState { localInfo: LocaleSetting; } export const useLocaleStore = defineStore({ id: 'shared-locale', persist: { // ζŒδΉ…εŒ– paths: ['localInfo'], }, state: (): LocaleState => ({ localInfo: context.localeSetting ?? localeSetting, }), getters: { getShowPicker(state): boolean { return !!state.localInfo?.showPicker; }, getLocale(state): LocaleType { return state.localInfo?.locale ?? 'zh_CN'; }, }, actions: { /** * Set up multilingual information and cache * @param info multilingual info */ setLocaleInfo(info: Partial) { this.localInfo = { ...this.localInfo, ...info }; }, /** * Initialize multilingual information and load the existing configuration from the local cache */ initLocale() { this.setLocaleInfo({ ...(context.localeSetting ?? localeSetting), ...this.localInfo, }); }, }, });