Missing langcode: how to send an email in the language you want?

Created on 17 March 2025, 19 days ago

Problem/Motivation

Thanks to the dev done in issue #3047790 πŸ“Œ Support email translations Needs review , email templates can now be translated.
Easy Email uses the website's current language to select the translated template, which works in almost all cases, such as user-driven events (registration, form submission, etc.).
However, it falls back to the site's default language when the event is not user-driven, like during cron jobs. As a result, the email is no longer received in the user's language.

Steps to reproduce

As a simplified use case, I'm using ECA and cron to send emails: all emails are sent using the website's default language.

Proposed resolution

  • Other Drupal entities have a "langcode" field, but Easy Email does not.
  • The ECA "Create new entity action" has a "Language" field that lists the website's enabled languages, but its value is not used by Easy Email.

Can these two be connected so we can send an email with a specific langcode?
This way, ECA could send the correct email.

Maybe there is a trick to tell Easy Email which language to use?

✨ Feature request
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡«πŸ‡·France PhilY πŸ‡ͺπŸ‡ΊπŸ‡«πŸ‡· Paris, France

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @PhilY
  • πŸ‡ΊπŸ‡ΈUnited States zengenuity

    Are you sending these emails to a user account on the site and want to use the language from their account settings? Does it work if you set the recipient_uid field on the easy email entity?

  • πŸ‡«πŸ‡·France PhilY πŸ‡ͺπŸ‡ΊπŸ‡«πŸ‡· Paris, France

    Are you sending these emails to a user account on the site and want to use the language from their account settings?
    Yes

    Does it work if you set the recipient_uid field on the easy email entity?
    The email is sent but in the website default language.

  • πŸ‡ΊπŸ‡ΈUnited States zengenuity

    I think there's an issue here, but the proper fix could be complex. Let's see if there's a workaround to solve your problem first.

    There's an ECA submodule called ECA Language. If you add the "Language: set code" action from that module into your model before you create the Easy Email, does that work? I think this action is supposed to switch the default language that the model is operating under.

  • πŸ‡«πŸ‡·France PhilY πŸ‡ͺπŸ‡ΊπŸ‡«πŸ‡· Paris, France

    add the "Language: set code"

    Perfect tip, that works!
    Thanks @zengenuity

Production build 0.71.5 2024