Skip to content

26 · Translatable string contains a javascript:// link – translations are rejected by locale

Project AI Content Suggestions (ai_content_suggestions)
Component Translation
Category Bug report
Priority Minor
Status Reported upstream as #3614006

Problem/Motivation

When importing German translations, locale reports:

Import of string "<a href="javascript://" class="toggle_content_suggestion_fields">Wählen Sie das/die Feld(er) aus, das/die Sie an den LLM senden möchten</a>" was skipped because of disallowed or malformed HTML.

The source string contains a javascript:// link, which locale_string_is_safe() rejects, so the translation never arrives. It is the description of the field selection in src/AiContentSuggestionsPluginBase.php (line 135 on 2.0.x):

'#description' => $this->t('<a href="javascript://" class="toggle_content_suggestion_fields">Select the field(s) you wish to send to the LLM</a>'),

js/ai_content_suggestions.js uses the class to show and hide the field list.

Steps to reproduce

  1. Install Drupal CMS in German with the CareSphere site template (AI enabled).
  2. Check the installation log for the message above.

Proposed resolution

Keep the markup out of the translatable string: translate only the label and render the element around it. A button also fits better than a link that goes nowhere, e.g.:

'#description' => [
  '#type' => 'html_tag',
  '#tag' => 'button',
  '#attributes' => ['type' => 'button', 'class' => ['link', 'toggle_content_suggestion_fields']],
  '#value' => $this->t('Select the field(s) you wish to send to the LLM'),
],
Copy to drupal.org

Issue title:

Translatable string contains a javascript:// link – translations are rejected by locale

Issue summary (paste it into the "Issue summary" field; project, component, category and priority are in the table above):

<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>When importing German translations, locale reports:</p>
<code>Import of string "<a href="javascript://" class="toggle_content_suggestion_fields">Wählen Sie das/die Feld(er) aus, das/die Sie an den LLM senden möchten</a>" was skipped because of disallowed or malformed HTML.</code>
<p>The source string contains a <code>javascript://</code> link, which <code>locale_string_is_safe()</code> rejects, so the translation never arrives. It is the description of the field selection in <code>src/AiContentSuggestionsPluginBase.php</code> (line 135 on 2.0.x):</p>
<code>'#description' => $this->t('<a href="javascript://" class="toggle_content_suggestion_fields">Select the field(s) you wish to send to the LLM</a>'),</code>
<p><code>js/ai_content_suggestions.js</code> uses the class to show and hide the field list.</p>
<h3 id="summary-steps-reproduce">Steps to reproduce</h3>
<ol>
<li>Install Drupal CMS in German with the CareSphere site template (AI enabled).</li>
<li>Check the installation log for the message above.</li>
</ol>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Keep the markup out of the translatable string: translate only the label and render the element around it. A button also fits better than a link that goes nowhere, e.g.:</p>
<code>'#description' => [
  '#type' => 'html_tag',
  '#tag' => 'button',
  '#attributes' => ['type' => 'button', 'class' => ['link', 'toggle_content_suggestion_fields']],
  '#value' => $this->t('Select the field(s) you wish to send to the LLM'),
],</code>