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
useIntl.ts•1.31 KiB
import configuration from '@intlayer/config/built';
import { bindIntl } from '@intlayer/core';
import type { LocalesValues } from '@intlayer/types';
import { IntlayerServerContext } from '../IntlayerServerProvider';
import { getServerContext } from '../serverContext';
/**
* React client hook that provides a locale-bound `Intl` object.
*
* It acts exactly like the native `Intl` object, but acts as a proxy to:
* 1. Inject the current locale automatically if none is provided.
* 2. Use the performance-optimized `CachedIntl` under the hood.
*
* @example
* ```tsx
* const intl = useIntl(); // uses context locale
*
* // Standard API, but no need to pass 'en-US' as the first argument
* const formatted = new intl.NumberFormat({
* style: 'currency',
* currency: 'USD'
* }).format(123.45);
* ```
*
* @example
* ```tsx
* const intl = useIntl();
*
* // You can still override the locale if needed
* const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());
* // or
* const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());
* ```
*/
export const useIntl = (locale?: LocalesValues) => {
const currentLocale = getServerContext<LocalesValues>(IntlayerServerContext);
return bindIntl(
locale ??
currentLocale ??
configuration?.internationalization?.defaultLocale
);
};