Problem/Motivation

#3439662: Allow a WebformEmailHandler to specify the language of an email message. added a language setting to the email handler so that, for example, staff notifications stay in the default language when a visitor submits a translated webform. The handler switches the config override language (setWebformTranslation()), so labels and option text come out in the chosen language. Two things still follow the submission and request language:

  • Tokens. getMessage() builds $token_options without langcode, so WebformTokenManager::setTokenOptions() falls back to the submission's language. [webform_submission:created] (the default body's "Submitted on …") then prints a translated weekday, for example "Mié, 30 Sep 2026" in an otherwise English email.
  • Strings formatted with t(). Element formatters such as BooleanBase::formatTextItem() return $this->t('Yes'), which uses the string translation's default language (the request language). A checkbox prints "Sí" in the English email.

Steps to reproduce

  1. Enable a second language (Spanish) and translate a webform that has a checkbox and an email handler using the default body.
  2. Set the email handler's language (Advanced → Language) to English.
  3. Submit the webform from the Spanish site (/es/…).
  4. The email is English, except "Submitted on" shows a Spanish weekday and the checkbox value is "Sí".

Proposed resolution

Make the handler's language reach both:

  • In getMessage(), when the handler has a language, pass it as $token_options['langcode'].
  • In setWebformTranslation(), also call setDefaultLangcode() on the string translation service. The existing call that restores the current language afterwards resets it.

With the handler language unset (the default), nothing changes. Tested on 6.3.1: an English submission's email is byte-identical before and after, and a Spanish submission's English-pinned email comes out fully English.

Remaining tasks

  • Merge request with the change and a test.
  • Review.

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork webform-3627178

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jmcerda created an issue. See original summary.

jmcerda’s picture

Status: Active » Needs review

MR !956 against 6.3.x. It passes the handler language as the token langcode in getMessage() and sets the string translation default in setWebformTranslation(). The existing restore call puts it back afterwards.

Tested on a 6.3.1 site with English and Spanish: with the email handler pinned to English, a Spanish submission now produces "Submitted on Wed, …" and "Yes" instead of "Mié" and "Sí", and the email is otherwise identical to an English submission. With no handler language set, output is byte-identical before and after (text and HTML). No test yet; a kernel test that submits in a second language and asserts the date token and a checkbox value would cover it.