with my custom module I try to prepare an email body containing hard coded plain text. The text should be translatable and formatted with line breaks for a nicer output. The text is prepared in my controller as following (for example):

$mail_body_plain['textpart'] = t('And much more...') . '\r\n';

php code sniffer gives me the warning:

Do not concatenate strings to translatable strings, they should be part of the t() argument and you should use placeholders

In my opinion every unnecessary format should be avoided to get parsed by t() function, to keep the Drupal translation database cleaner. But it seems, that my approach violates Drupal's coding standards.

What is here the right solution?

Thanks in advance

  • 1
    It will be better to use the Swift Mailer module (for sending HTML emails with twig templates), and implements {% trans %}And much more...{% endtrans %} texts. Feb 5 at 18:13
  • I will use swiftmailer, but I need a separate mail string for plaintext version. In the plaintext version I would like to use dashes for listings. in twig I can use {% if is_html %} to play with output.
    – dercheffe
    Feb 5 at 18:17
  • 1
    Then, how about provide strings into a simple array and display it with the implode("\n", $strings) PHP function, seems it should work for plain version. Feb 5 at 18:19
  • I will try it thx :)
    – dercheffe
    Feb 5 at 18:22
  • Thanks @IvanTibezh your suggestions works wonderful :) For listings I achieved also line-breaks for each element: I created a multidimensional array first and used implode() then here also.
    – dercheffe
    Feb 5 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.