PluginProbe
The Innovative Form Builder – IvyForms / 0.6.1-backup
The Innovative Form Builder – IvyForms v0.6.1-backup
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / frontend / src / composables / useLabels.ts

useLabels.ts in The Innovative Form Builder – IvyForms 0.6.1-backup, at frontend/src/composables/useLabels.ts

35 lines 982 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useLabelsStore } from '@/stores/labels'
2 import { getActivePinia } from 'pinia'
3
4 /**
5 * Composable function to provide easy access to labels throughout the application
6 * @returns Object with getLabel function and allLabels getter
7 */
8 export function useLabels() {
9 // Check if Pinia is available
10 if (!getActivePinia()) {
11 //console.warn('Pinia is not initialized. Labels will not be available.')
12 return {
13 getLabel: (key: string, fallback: string = '') => fallback || key,
14 allLabels: {},
15 }
16 }
17
18 const labelsStore = useLabelsStore()
19
20 /**
21 * Get a label by key with optional fallback value
22 * @param key The label key to retrieve
23 * @param fallback Optional fallback text if label doesn't exist
24 * @returns The label string or fallback value
25 */
26 const getLabel = (key: string, fallback: string = ''): string => {
27 return labelsStore.getLabel(key, fallback)
28 }
29
30 return {
31 getLabel,
32 allLabels: labelsStore.allLabels,
33 }
34 }
35