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_optionswithoutlangcode, soWebformTokenManager::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
- Enable a second language (Spanish) and translate a webform that has a checkbox and an email handler using the default body.
- Set the email handler's language (Advanced → Language) to English.
- Submit the webform from the Spanish site (
/es/…). - 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 callsetDefaultLangcode()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
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
Comment #3
jmcerdaMR !956 against 6.3.x. It passes the handler language as the token
langcodeingetMessage()and sets the string translation default insetWebformTranslation(). 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.