transX
A trans variant pre-bound to jsxConverter. Use per call when the global converter is left as plainConverter and only specific call sites need JSX.
Signature
function transX(keyword: string, placeholders?: any): string | React.ReactNode[];What it does
transX is exactly equivalent to:
import { getTranslationLocaleCode, transFrom } from "@mongez/localization";import { jsxConverter } from "@mongez/react-localization";
transFrom(getTranslationLocaleCode(), keyword, placeholders, jsxConverter);It hard-codes jsxConverter as the converter argument, ignoring setLocalizationConfigurations({ converter }). That’s the entire point.
Example
import { extend, trans, plainTrans } from "@mongez/localization";import { transX } from "@mongez/react-localization";
extend("en", { agreeToTerms: "By clicking, you agree to our :tos",});
// Stays as plain string — global converter is plainConverter (default).trans("agreeToTerms", { tos: "Terms" });// → "By clicking, you agree to our Terms"
// Same call site, JSX placeholder via transX.transX("agreeToTerms", { tos: <a href="/terms">Terms</a> });// → React fragment array, rendered as a real <a> in the DOM.
// Force the plain converter even if the global one is jsxConverter.plainTrans("agreeToTerms", { tos: "Terms" });// → "By clicking, you agree to our Terms"What transX does NOT do
- Does not subscribe to locale changes. It’s a plain function call — it reads
getTranslationLocaleCode()once at call time and returns. A component that already rendered will keep its old translation until something re-renders it. Seerecipesfor re-render patterns. - Does not respect a per-call converter argument. The converter is
jsxConverter, always. If you need a different converter, calltransFrom(...)directly. - Does not coerce return types. If placeholders is empty / primitive, you get a string back; otherwise you get an array of React fragments. Consumers must handle both.
Inheritance from transFrom
Because transX delegates to transFrom, it inherits:
- Locale resolution via
getTranslationLocaleCode()(which reads either the configuredtranslationLocalCodeorgetCurrentLocaleCode()). - Fallback locale handling (configured via
setFallbackLocaleCode). - Missing-keyword fallback (returns the keyword itself if nothing resolves).
- Count-based pluralization (when
placeholders.countis set). - Object-shaped keyword support (
trans({ en: "Hello", ar: "مرحبا" })).
In other words, every feature of @mongez/localization works through transX exactly as it would through trans — only the converter is locked in.