{"version":3,"file":"tx.mjs","names":[],"sources":["../../../src/server-dir/runtime/tx.ts"],"sourcesContent":["import type {\n  FormatVariables,\n  StringFormat,\n} from '@generaltranslation/format/types';\nimport { txInternal } from 'gt-i18n/internal';\nimport { getRequestConditions } from '../../request/getRequestConditions';\n\ntype TxOptions = FormatVariables & {\n  $locale?: string;\n  $context?: string;\n  $maxChars?: number;\n  $format?: StringFormat;\n};\n\n/**\n * Translates the provided content string based on the specified locale and options.\n * If no translation is required, it renders the content as is. Otherwise, it fetches the\n * required translations or falls back to on-demand translation if enabled.\n *\n * @async\n * @function tx (translate)\n *\n * @param {string} content - The content string that needs to be translated.\n * @param {Object} [options] - Translation options.\n * @param {string} [options.$locale] - The target locale for translation. Defaults to the current locale if not provided.\n * @param {string} [options.$context] - Additional context for the translation process, which may influence the translation's outcome.\n * @param {number} [options.$maxChars] - The maximum number of characters to translate.\n * @param {string|number|boolean|Date} [options.<variable>] - Variables to interpolate into the message, passed as top-level keys (e.g. `{ price: 29.99 }`).\n * @param {StringFormat} [options.$format] - The data format for the message. ICU formatting is only applied when explicitly requested with `$format: 'ICU'`.\n *\n * @returns {Promise<string>} - A promise that resolves to the translated content string, or the original content if no translation is needed.\n *\n * @throws {Error} - Throws an error if the translation process fails or if there are issues with fetching necessary data.\n *\n * @example\n * // Basic usage with default locale detection\n * const translation = await tx(\"Hello, world!\");\n *\n * @example\n * // Providing specific translation options\n * const translation = await tx(\"Hello, world!\", { $locale: 'es', $context: 'Translate informally' });\n *\n * @example\n * // Using variables in the content string\n * const translation = await tx(\"The price is {price}\", { $locale: 'es-MX', price: 29.99 });\n */\nexport async function tx(\n  message: string,\n  options: TxOptions = {}\n): Promise<string> {\n  const { _locale, _enableI18n } = await getRequestConditions();\n  return txInternal({\n    locale: _locale,\n    enableI18n: _enableI18n,\n    content: message,\n    options,\n  });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,eAAsB,GACpB,SACA,UAAqB,EAAE,EACN;CACjB,MAAM,EAAE,SAAS,gBAAgB,MAAM,sBAAsB;AAC7D,QAAO,WAAW;EAChB,QAAQ;EACR,YAAY;EACZ,SAAS;EACT;EACD,CAAC"}