# ivyforms/0.3.1/frontend/src/composables/useLabels.ts

The Innovative Form Builder – IvyForms, version 0.3.1. 35 lines.

- Page: https://pluginprobe.com/plugins/ivyforms/0.3.1/code/frontend/src/composables/useLabels.ts
- Raw: https://pluginprobe.com/plugins/ivyforms/0.3.1/raw/frontend/src/composables/useLabels.ts
- Modified: 2025-09-04T07:37:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/ivyforms/0.3.1/code/frontend/src/composables/useLabels.ts#L10-L20`.

```typescript
import { useLabelsStore } from '@/stores/labels'
import { getActivePinia } from 'pinia'

/**
 * Composable function to provide easy access to labels throughout the application
 * @returns Object with getLabel function and allLabels getter
 */
export function useLabels() {
  // Check if Pinia is available
  if (!getActivePinia()) {
    console.warn('Pinia is not initialized. Labels will not be available.')
    return {
      getLabel: (key: string, fallback: string = '') => fallback || key,
      allLabels: {},
    }
  }

  const labelsStore = useLabelsStore()

  /**
   * Get a label by key with optional fallback value
   * @param key The label key to retrieve
   * @param fallback Optional fallback text if label doesn't exist
   * @returns The label string or fallback value
   */
  const getLabel = (key: string, fallback: string = ''): string => {
    return labelsStore.getLabel(key, fallback)
  }

  return {
    getLabel,
    allLabels: labelsStore.allLabels,
  }
}

```
