Template Segment
mainA Template Segment is used to manage the structure of rich text fields and blocks. It is an HTML blob that preserves the layout while marking where translated text should be inserted.
Instead of translating the HTML directly, Wagtail localize extracts the text into String Segments and replaces them in the template with <text> tags containing a position attribute. This allows the system to recombine the translated strings with the original HTML structure.
Key behaviors:
- Block tags (e.g.,
<p>,<li>,<h1>) are left in the template. - Inline tags (e.g.,
<b>,<a>) are extracted along with the string segments. However, if an inline tag completely encapsulates a string segment, that tag remains in the template. - Non-translatable elements like images or embeds are preserved in the template.
<h1><text position="0"></h1>
<p>
<text position="1">
<ul>
<li><b><text position="2"></b></li>
</ul>
</p>