Custom e-mail translation in Drupal 8 I need to send some e-mails depending on some actions. These e-mails should be translated depending on the target user's preferred language. I've seen that the mail function has a language parameter, but for me, it's not really do anything.

  $renderArray = [
    '#theme' =&gt; 'email_notification_content_update',
    '#name' =&gt; $node-&gt;getOwner()-&gt;getDisplayName(),
    '#content_title' =&gt; $node-&gt;getTitle(),
    '#content_url' =&gt; $node-&gt;toUrl('canonical', ['absolute' =&gt; TRUE])
      -&gt;toString(),
    '#unfollow_url' =&gt; Url::fromRoute('flag.field_entry.delete', [
      'flag' =&gt; 'flag_name',
      'entity_id' =&gt; $node-&gt;id(),
    ])-&gt;setAbsolute()-&gt;toString(),
  ];

  $this-&gt;mailManager-&gt;mail(
    'my_module',
    'email_notification_content_update',
    $follower-&gt;getEmail(),
    $follower-&gt;language()-&gt;getId(),
    [
      'body' =&gt; $this-&gt;renderer-&gt;renderRoot($renderArray),
      'subject' =&gt; $this-&gt;t('An update of the content @title has been updated.', ['@title' =&gt; $node-&gt;getTitle()]),
    ]
  );


Currently, the e-mail text is in twig file (with links) and the parameters are passed to it at render. Now I can put the whole twig file in {% trans %} tags, but is there a better way? Like using the mail function's language parameter? Is there a better way to make a custom e-mail sending and have translations to them?
Be aware that the rendering (and therefore the translation) happens at $this->renderer->renderRoot(). I'd create a mail key handler, and build the body inside that handler. I'm not sure, but it may be that drupal switches to the given language at the ->mail function before processing the custom hook.

  $this-&gt;mailManager-&gt;mail(
    'mymodule',
    'content_update',
    $follower-&gt;getEmail(),
    $follower-&gt;language()-&gt;getId(),
    [
      'node' =&gt; $node,
    ]
  );



/mymodule.module

&lt;?php

use Drupal\Core\Url;

/**
 * Implements hook_mail().
 */
function mymodule_mail($key, &amp;$message, $params) {
  $renderer = Drupal::service('renderer');

  if ($key === 'content_update') {
    $node = $params['node'];
    $renderArray = [
      '#theme' =&gt; 'email_notification_content_update',
      '#name' =&gt; $node-&gt;getOwner()-&gt;getDisplayName(),
      '#content_title' =&gt; $node-&gt;getTitle(),
      '#content_url' =&gt; $node-&gt;toUrl('canonical', ['absolute' =&gt; TRUE])
        -&gt;toString(),
      '#unfollow_url' =&gt; Url::fromRoute('flag.field_entry.delete', [
        'flag' =&gt; 'flag_name',
        'entity_id' =&gt; $node-&gt;id(),
      ])-&gt;setAbsolute()-&gt;toString(),
    ];
    $message['body'] = $renderer-&gt;renderRoot($renderArray);
    $message['subject'] = t("Content :title has been updated", [':title' =&gt; $node-&gt;label()]),
  }
}