1

I created a custom D8 module with all text strings declared in English, either via this->t(), t() or in various configuration (YML) files.

I am now in the process of translating those strings in French so that I can then extract them and package them with the module.

My issue: some strings for the interface contain HTML links (mostly refering to other Drupal admin pages); they display and work fine in English, but when I try to translate those strings via the Drupal UI, I get an error saying "The submitted string contains disallowed HTML". If I remove the <a> then the error disappears.

Here's an example of a string containing several links:

$this->t('<p>Some explanations here. You can find a more information 
  <a href=@hhelp>on the help page</a>.<br>Note: after changing this value, 
  you may have to <a href=@hperformance>clear the cache</a> for this setting 
  to take effect.</p>', array(
  '@hhelp' => '../../help/mymodule',
  '@hperformance' => '../development/performance',
)),

Is it possible to translate those strings while keeping the links in the translation? How should I proceed?

2 Answers 2

3

the problem is the absence of the quotes. I try to insert this traslation on a drupal site and it work!

<p>Some explanations here. You can find a more information 
 <a href='@hhelp'>on the help page</a>.<br>Note: after changing this 
  value,you may have to <a href='@hperformance'>clear the cache</a> 
  for this setting to take effect.</p>

It also work with "

1
  • You're right, thanks. That was a really silly mistake. Weird that it works without the quote, though (in the PHP).
    – s427
    Commented Nov 30, 2018 at 8:58
0

Have you tried split the string as below

$text = t('Some explanations here. You can find a more information 
<a href="@hhelp">on the help page</a>.', array('@hhelp' =>'../../help/mymodule',));

$text.= t('<br>Note: after changing this value, you may have to <a href="@hperformance">
clear the cache</a> for this setting 
to take effect.', array('@hperformance' => '../development/performance',));
1
  • Thanks but the issue is not because there are two links. It also occurs when there's only one link. (Problem solved though, it was because of missing quotes around the href value.)
    – s427
    Commented Nov 30, 2018 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.