Skip to main content
Glama
useIntlayer.ts1.08 kB
import type { DictionaryKeys, DictionaryRegistryContent, LocalesValues, } from '@intlayer/types'; import { derived, type Readable } from 'svelte/store'; import { getIntlayer } from '../getIntlayer'; import type { DeepTransformContent } from '../plugins'; import { getIntlayerContext } from './intlayerContext'; import { intlayerStore } from './intlayerStore'; /** * Svelte hook that picks one dictionary by its key and returns reactive content * @param key The dictionary key to retrieve * @param locale The target locale (optional, uses context or store locale) * @returns Reactive store with transformed dictionary content */ export const useIntlayer = <T extends DictionaryKeys>( key: T, locale?: LocalesValues ): Readable<DeepTransformContent<DictionaryRegistryContent<T>>> => { 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 getIntlayer(key, 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