Skip to main content
Don't forget to restore the language manager for the remainder of the request.
Source Link

The field labels are used from the config translation system. You also need to set the config override language. See user_mail() in core.

  // Temporarily alter the language manager.
  $language_manager = \Drupal::languageManager();
  $langcode = $message['langcode'];
  $variables = array('user' => $params['account']);

  $language = \Drupal::languageManager()->getLanguage($params['account']->getPreferredLangcode());
  $original_language = $language_manager->getConfigOverrideLanguage();
  $language_manager->setConfigOverrideLanguage($language);
  $mail_config = \Drupal::config('user.mail');

  // Restore the language manager.
  $language_manager->setConfigOverrideLanguage($original_language);

The field labels are used from the config translation system. You also need to set the config override language. See user_mail() in core.

  $language_manager = \Drupal::languageManager();
  $langcode = $message['langcode'];
  $variables = array('user' => $params['account']);

  $language = \Drupal::languageManager()->getLanguage($params['account']->getPreferredLangcode());
  $original_language = $language_manager->getConfigOverrideLanguage();
  $language_manager->setConfigOverrideLanguage($language);
  $mail_config = \Drupal::config('user.mail');

The field labels are used from the config translation system. You also need to set the config override language. See user_mail() in core.

  // Temporarily alter the language manager.
  $language_manager = \Drupal::languageManager();
  $langcode = $message['langcode'];
  $variables = array('user' => $params['account']);

  $language = \Drupal::languageManager()->getLanguage($params['account']->getPreferredLangcode());
  $original_language = $language_manager->getConfigOverrideLanguage();
  $language_manager->setConfigOverrideLanguage($language);
  $mail_config = \Drupal::config('user.mail');

  // Restore the language manager.
  $language_manager->setConfigOverrideLanguage($original_language);
added link to the documentation, and the relevant code from that function
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

The field labels are used from the config translation system. You also need to set the config override language. See user_mail()user_mail() in core.

  $language_manager = \Drupal::languageManager();
  $langcode = $message['langcode'];
  $variables = array('user' => $params['account']);

  $language = \Drupal::languageManager()->getLanguage($params['account']->getPreferredLangcode());
  $original_language = $language_manager->getConfigOverrideLanguage();
  $language_manager->setConfigOverrideLanguage($language);
  $mail_config = \Drupal::config('user.mail');

The field labels are used from the config translation system. You also need to set the config override language. See user_mail() in core.

The field labels are used from the config translation system. You also need to set the config override language. See user_mail() in core.

  $language_manager = \Drupal::languageManager();
  $langcode = $message['langcode'];
  $variables = array('user' => $params['account']);

  $language = \Drupal::languageManager()->getLanguage($params['account']->getPreferredLangcode());
  $original_language = $language_manager->getConfigOverrideLanguage();
  $language_manager->setConfigOverrideLanguage($language);
  $mail_config = \Drupal::config('user.mail');
Source Link

The field labels are used from the config translation system. You also need to set the config override language. See user_mail() in core.