| 1 |
import { defineStore } from 'pinia' |
| 2 |
|
| 3 |
// Note: Window.wpIvyLabels is defined in src/types/global.d.ts |
| 4 |
// No need to duplicate declaration here |
| 5 |
|
| 6 |
export const useLabelsStore = defineStore('labels', { |
| 7 |
state: () => ({ |
| 8 |
labels: {} as Record<string, string>, |
| 9 |
}), |
| 10 |
actions: { |
| 11 |
initialize() { |
| 12 |
// Get labels from the global variable injected by WordPress |
| 13 |
if (typeof window.wpIvyLabels !== 'undefined') { |
| 14 |
this.labels = window.wpIvyLabels |
| 15 |
} |
| 16 |
}, |
| 17 |
getLabel(key: string, fallback: string = ''): string { |
| 18 |
return this.labels[key] || fallback |
| 19 |
}, |
| 20 |
}, |
| 21 |
getters: { |
| 22 |
allLabels: (state) => state.labels, |
| 23 |
}, |
| 24 |
}) |
| 25 |
|