Skip to main content
Glama
useIntlayer.ts1.27 kB
import { computed, inject } from '@angular/core'; import type { DictionaryKeys, DictionaryRegistryContent, LocalesValues, } from '@intlayer/types'; import { getIntlayer } from '../getIntlayer'; import type { DeepTransformContent } from '../plugins'; import { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer'; /** guard utility - true only for objects generated by `renderIntlayerNode()` */ export const isUpdatableNode = ( val: unknown ): val is { __update: (n: unknown) => void } => !!val && typeof val === 'object' && typeof (val as any).__update === 'function'; export const useIntlayer = <T extends DictionaryKeys, L extends LocalesValues>( key: T, locale?: LocalesValues ): DeepTransformContent<DictionaryRegistryContent<T>> => { const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN)!; /** which locale should we use right now? */ const localeTarget = computed(() => locale ?? intlayer.locale()); /** a *stable* reactive dictionary object */ // @ts-ignore Type instantiation is excessively deep and possibly infinite const content = computed(() => getIntlayer<T, L>(key, localeTarget() as L)); return content() as DeepTransformContent<DictionaryRegistryContent<T>>; // all consumers keep full reactivity };

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