October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

React i18next Component: When and How to Use It

Use React i18next’s for cohesive translations that contain React elements; use t() for plain text. Learn how tags, interpolation, plurals, and key props work.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use React i18next’s <Trans> when a sentence needs to be translated as a whole and includes React elements such as a link or formatting. For plain text, use t(). <Trans> handles interpolation, but it does not load translations or rerender a component when the language changes; use useTranslation or withTranslation for that integration.

When should you use <Trans> instead of t()?

Choose <Trans> when translators need to rearrange text and React elements together as one sentence—for example, a sentence containing a link or emphasized phrase. Choose t() when the value is ordinary text without React nodes embedded in it. The step-by-step guide describes <Trans> as translating a JSX tree in one translation.

<Trans> obtains a suitable t() function from the context instance or global instance by default. Pass an i18n or t prop to override that choice. For translation loading and language-change rerendering, connect the component with useTranslation or withTranslation; these are among the integration patterns in the quick-start guide.

How do JSX children become translation tags?

<Trans> converts its child tree into a translation string. Text remains text, interpolation objects become interpolation values, and React elements wrap their children in tags corresponding to their positions in the child array. A link may therefore appear in the resource as an indexed tag such as <1>...</1>. If you reorder the JSX children, the generated index can change, so keep the translation resource aligned with the component tree.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use named components when indexes are hard to maintain

For a more readable resource, pass a components object and refer to its keys in the translation, such as italic or bold. The documentation cautions that existing self-closing HTML tag names are reserved and should not be used as mapping keys. An array form uses numeric component indexes and can be useful with ICU syntax. The reference notes IcuTrans in connection with the ICU macro, but does not recommend direct use of IcuTrans.

Simple HTML nodes may stay readable

With transSupportBasicHtmlNodes enabled, simple nodes such as <br/>, <strong>, <i>, and <p> may be retained in translation strings when they have no extra attributes and meet the documented child constraints. More complex elements are represented as indexed nodes. transKeepBasicHtmlNodesFor controls which basic nodes are retained when generating default values.

How do interpolation and plurals work?

Interpolate values

Interpolation values can be placed in the children or passed through the values prop. The TypeScript reference describes a workaround that casts an interpolation object to a suitable record type or any. Setting TypeScript’s allowObjectInHTMLChildren is another option, but it weakens type safety globally.

Pass a count for pluralizable text

For pluralized text, provide a numeric count. According to the component reference, beginning with react-i18next v16.4.0, count can be inferred when {{ count }} appears in children. Inference requires a JavaScript number. An explicit count takes precedence, including count={0}; when using a key without children, the count prop is still required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep generated lists out of default strings

When children are generated with Array.map(), put i18nIsDynamicList on the wrapping element. This tells the nodeToString path used by saveMissing not to include generated list children in the default string.

Which props and configuration settings matter?

The reference lists these optional props: i18nKey, ns, t, count, context, tOptions, parent, i18n, defaults, values, components, shouldUnescape, and transDefaultProps. Although the API marks them optional, provide a key when natural-language text is not serving as the key. When using natural-language keys, the docs recommend a dedicated ns prop instead of embedding the namespace in i18nKey.

transWrapTextNodes can wrap text nodes in an element such as span. The docs describe it as a workaround for a Google Translate issue: DOM manipulation by the translation tool can conflict with React. For React 15 or earlier, set defaultTransParent or pass parent.

How can you troubleshoot an unexpected translation string?

  1. Inspect the <Trans> instance and its props.children in React Developer Tools to see the actual child tree.
  2. Enable debug = true in i18next initialization to inspect debug output.
  3. Use saveMissing to help reveal the generated default string and any tag indexes.
  4. Compare the child order with the indexed tags in the resource; React element positions determine which index each tag uses.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What happened to the older Interpolation component?

The migration guide says the older Interpolation component was deprecated, replaced by <Trans>, and removed in react-i18next v10. See Migrating from v9 to v10.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For the full API, consult the Trans Component reference. The i18next instance documentation also describes the relevant basic-node configuration.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.