react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
41 lines (38 loc) • 1.31 kB
JavaScript
'use client';
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
let react = require("react");
//#region src/client/t.ts
/**
* Client-side translation function that returns the translation of the provided multilang content.
*
* If the locale is not provided, it will use the locale from the client context.
*
* @param multilangContent - An object mapping locales to their respective content.
* @param locale - Optional locale to override the current context locale.
* @returns The translation for the specified locale.
*
* @example
* ```tsx
* import { t } from 'react-intlayer';
*
* const MyComponent = () => {
* const greeting = t({
* en: 'Hello',
* fr: 'Bonjour',
* es: 'Hola',
* });
*
* return <h1>{greeting}</h1>;
* };
* ```
*/
const t = (multilangContent, locale) => {
const { locale: currentLocale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
return (0, _intlayer_core_interpreter.getTranslation)(multilangContent, locale ?? currentLocale);
};
//#endregion
exports.t = t;
//# sourceMappingURL=t.cjs.map