Skip to main content
Glama
useDictionary.ts1.06 kB
import type { Dictionary, LocalesValues } from '@intlayer/types'; import { derived, type Readable } from 'svelte/store'; import { getDictionary } from '../getDictionary'; import type { DeepTransformContent } from '../plugins'; import { getIntlayerContext } from './intlayerContext'; import { intlayerStore } from './intlayerStore'; /** * Svelte hook that transforms a dictionary and returns reactive content * @param dictionary The dictionary to transform * @param locale The target locale (optional, uses context or store locale) * @returns Reactive store with transformed dictionary content */ export const useDictionary = <T extends Dictionary>( dictionary: T, locale?: LocalesValues ): Readable<DeepTransformContent<T['content']>> => { const context = getIntlayerContext(); // Create a derived store that reactively updates when locale changes return derived([intlayerStore], ([$store]) => { const targetLocale = locale ?? context?.locale ?? $store.locale; return getDictionary<T, LocalesValues>(dictionary, targetLocale); }); };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aymericzip/intlayer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server