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