Skip to main content
Glama
useDictionaryDynamic.ts1.11 kB
import configuration from '@intlayer/config/built'; import type { DeclaredLocales, Dictionary, LocalesValues, StrictModeLocaleMap, } from '@intlayer/types'; import { IntlayerServerContext } from './IntlayerServerProvider'; import { getServerContext } from './serverContext'; import { useDictionary } from './useDictionary'; import { useLoadDynamic } from './useLoadDynamic'; /** * On the server side, Hook that transform a dictionary and return the content * * If the locale is not provided, it will use the locale from the server context */ export const useDictionaryDynamic = < T extends Dictionary, L extends LocalesValues = DeclaredLocales, >( dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>, key: string, locale?: L ) => { const localeTarget = locale ?? getServerContext<LocalesValues>(IntlayerServerContext) ?? configuration?.internationalization.defaultLocale; const dictionary = useLoadDynamic<T>( `${String(key)}.${localeTarget}`, (dictionaryPromise as any)[localeTarget]?.() ); return useDictionary<T, L>(dictionary, localeTarget as L); };

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