Skip to main content
Glama
useDictionaryAsync.ts1.17 kB
'use client'; import configuration from '@intlayer/config/built'; import type { Dictionary, LocalesValues, StrictModeLocaleMap, } from '@intlayer/types'; import { useContext, useMemo } from 'preact/hooks'; import { IntlayerClientContext } from './IntlayerProvider'; import { useDictionary } from './useDictionary'; /** * 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 client context */ export const useDictionaryAsync = async <T extends Dictionary>( dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>, locale?: LocalesValues ): Promise<T> => { const { locale: currentLocale } = useContext(IntlayerClientContext); const localeTarget = useMemo( () => locale ?? currentLocale ?? configuration?.internationalization.defaultLocale, [currentLocale, locale] ); const dictionary = await useMemo( async () => (await dictionaryPromise[ localeTarget as keyof typeof dictionaryPromise ]?.()) as T, [dictionaryPromise, localeTarget] ); return useDictionary(dictionary, localeTarget) as any; };

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