react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
35 lines (33 loc) • 1.25 kB
JavaScript
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
const require_server_serverContext = require('./serverContext.cjs');
const require_server_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
let _intlayer_core = require("@intlayer/core");
//#region src/server/t.ts
/**
* On the server side, hook to get the translation content based on the locale
*
* 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:
*
* ```ts
* const content = t<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 t = (multilangContent, locale) => {
const currentLocale = require_server_serverContext.getServerContext(require_server_IntlayerServerProvider.IntlayerServerContext);
return (0, _intlayer_core.getTranslation)(multilangContent, locale ?? currentLocale);
};
//#endregion
exports.t = t;
//# sourceMappingURL=t.cjs.map