<p>You can move those HTML parts to parameters themselves.</p>
<p><strong>Template:</strong></p>
<pre><code>{{ 'Lorem ipsum. {linkTagBegin}Aenean commodo ligula{linkTagEnd} eget dolor.'|t({
    linkTagBegin: '&lt;a href=&quot;#&quot; target=&quot;_blank&quot;&gt;',
    linkTagEnd: '&lt;/a&gt;'
})|raw }}
</code></pre>
<p><strong>Translation PHP file:</strong></p>
<pre class="lang-php prettyprint-override"><code>&lt;?php

return [
    'Lorem ipsum. {linkTagBegin}Aenean commodo ligula{linkTagEnd} eget dolor.' =&gt; 'EN Lorem ipsum. {linkTagBegin}EN Aenean commodo ligula{linkTagEnd} EN eget dolor.'
];
</code></pre>
<p><strong>Result (bold part is the link):</strong></p>
<blockquote>
<p>EN Lorem ipsum. <strong>EN Aenean commodo ligula</strong> EN eget dolor.</p>
</blockquote>
<p>So in the end the HTML is part of template file.</p>

CC BY-SA 4.0
2024-02-20T12:50:57.297Z
2024-02-20T12:50:57.297Z
muffir
<p>I have a block of text I'd like to make translatable. Within that block of text there is a link.</p>

<p>The following works:</p>

<pre><code>{{ "Lorem ipsum. &lt;a href='{url}' target='_blank'&gt;Aenean commodo ligula&lt;/a&gt; eget dolor."|t({
    url: "#"
})|raw }}
</code></pre>

<p>But doesn't feel like the best way to do it as the translation file now requires HTML:</p>

<pre><code>craft/translations/en_us.php

&lt;?php

return array(
    "Lorem ipsum. &lt;a href='{url}' target='_blank'&gt;Aenean commodo ligula&lt;/a&gt; eget dolor." =&gt; "Lorem ipsum. &lt;a href='{url}' target='_blank'&gt;Aenean commodo ligula&lt;/a&gt; eget dolor."
);
</code></pre>

<p>Are there any other ways to do this that lead to a better separation of translatable text and HTML that relates to how the translator can interact with that text?</p>

CC BY-SA 3.0
2016-09-01T03:33:36.637Z
If you find a better way, let us know.  That's how we do it in the handful of places strings that need translating that have markup in them.
Brad Bell
<localization>
What is the best way to make text that has html translatable?
# What is the best way to make text that has html translatable?

(Asked by: username_0 on 2016-09-01)

I have a block of text I'd like to make translatable. Within that block of text there is a link.
The following works:
{{ "Lorem ipsum. Aenean commodo ligula eget dolor."|t({
    url: "#"
})|raw }}

But doesn't feel like the best way to do it as the translation file now requires HTML:
craft/translations/en_us.php

Aenean commodo ligula eget dolor." => "Lorem ipsum. Aenean commodo ligula eget dolor."
);

Are there any other ways to do this that lead to a better separation of translatable text and HTML that relates to how the translator can interact with that text?

**Tags:** localization
> **Comments:**
> **username_1**: If you find a better way, let us know.  That's how we do it in the handful of places strings that need translating that have markup in them.  

---

## 1 answers

### Answer by username_2 on 2024-02-20. Score: 1

You can move those HTML parts to parameters themselves.
Template:
{{ 'Lorem ipsum. {linkTagBegin}Aenean commodo ligula{linkTagEnd} eget dolor.'|t({
    linkTagBegin: '',
    linkTagEnd: ''
})|raw }}

Translation PHP file:
 'EN Lorem ipsum. {linkTagBegin}EN Aenean commodo ligula{linkTagEnd} EN eget dolor.'
];

Result (bold part is the link):

EN Lorem ipsum. EN Aenean commodo ligula EN eget dolor.

So in the end the HTML is part of template file.


---

