UNPKG

react-intlayer

Version:

Easily internationalize i18n your React applications with type-safe multilingual content management.

35 lines (33 loc) 1.28 kB
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs'); const require_client_IntlayerProvider = require('./IntlayerProvider.cjs'); let react = require("react"); let _intlayer_core = require("@intlayer/core"); //#region src/client/useTraduction.ts /** * On the client side, Hook that picking one dictionary by its id and return the content. * * If not locale found, it will return the content related to the default locale. * * Return either the content editor, or the content itself depending on the configuration. * * Usage: * * ```tsx * const content = useTranslation<string>({ * en: 'Hello', * fr: 'Bonjour', * }, 'fr'); * // 'Bonjour' * ``` * * Using TypeScript: * - this function will require each locale to be defined if defined in the project configuration. * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found. */ const useTranslation = (languageContent) => { const { locale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext); return (0, react.useMemo)(() => (0, _intlayer_core.getTranslation)(languageContent, locale), [languageContent, locale]); }; //#endregion exports.useTranslation = useTranslation; //# sourceMappingURL=useTraduction.cjs.map