Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-20T12:50:57.297Z
Answers.LastActivityDate: 2024-02-20T12:50:57.297Z
Answers.UserDisplayName: muffir
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-09-01T03:33:36.637Z
Comments.Text: 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.
Comments.UserDisplayName: Brad Bell
Tags: <localization>
Title: What is the best way to make text that has html translatable?
ThreadText: # 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. <a href='{url}' target='_blank'>Aenean commodo ligula</a> 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
  
  <?php
  
  return array(
      "Lorem ipsum. <a href='{url}' target='_blank'>Aenean commodo ligula</a> eget dolor." => "Lorem ipsum. <a href='{url}' target='_blank'>Aenean commodo ligula</a> 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: '<a href="#" target="_blank">',
      linkTagEnd: '</a>'
  })|raw }}
  
  ```
  
  **Translation PHP file:**
  
  ```php
  <?php
  
  return [
      'Lorem ipsum. {linkTagBegin}Aenean commodo ligula{linkTagEnd} eget dolor.' => '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.
  
  
  ---
  
  