Skip to content

i18n/t-fragment

Translates one whole sentence whose placeholders are DOM nodes, so translators get the full sentence and can move each node wherever their language needs it.

Function Description
tFragment Translates a sentence like t, but places DOM nodes at its \{\{name\}\} placeholders. Each key of nodes is a placeholder of the translated sentence. Its value is placed where the translation puts that placeholder, so 'Running for \{\{duration\}\} milliseconds' and a translation that moves \{\{duration\}\} to the end both render correctly. Every other placeholder is interpolated by i18next as usual, from options. A Node placeholder used more than once is placed at its first position and deep-cloned at the later ones; a builder runs once per position. A placeholder the translation leaves out is not placed at all.
Type Description
TranslationNode A DOM value of a tFragment placeholder: a node placed as is, or a builder that appends the node to the fragment at the placeholder’s position.