Set langcode with LegacyEmailBuilder

Created on 8 January 2024, 12 months ago
Updated 9 August 2024, 4 months ago

Problem/Motivation

When using LegacyEmailBuilder, the email langcode is always set to the current langcode. Since a langcode is provided to the mail method on the MailManager, we should use that langcode.

Proposed resolution

Use the legacy message langcode during the processing in Mailer.

โœจ Feature request
Status

Needs work

Version

1.4

Component

Code

Created by

๐Ÿ‡จ๐Ÿ‡ญSwitzerland aerzas

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

Merge Requests

Comments & Activities

  • Issue created by @aerzas
  • Status changed to Needs review 12 months ago
  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland aerzas

    Here is a patch proposition.

  • Status changed to Needs work 11 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom adamps

    Thanks for the issue and patch. Strange, I thought I had written code for this already๐Ÿ˜ƒ.

    The issue is only about LegacyEmailBuilder so the fix should also be in the legacy code. I believe we can fix it in LegacyMailerHelper::emailFromArray(). On line 141 there is a call to $email->setAddress(). We can pass a second parameter of $message['langcode']. This should be only for the to address.

    This project now uses merge requests not patches please.

  • First commit to issue fork.
  • Status changed to Needs review 11 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia viren18febS

    This project now uses merge requests not patches please.

    Please review.

  • Status changed to Needs work 11 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom adamps

    Thanks, I mean pass langcode as second parameter to parseAddress()

  • Status changed to Needs review 11 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia viren18febS

    I have updated langcode as second parameter to parseAddress(), please review.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom adamps

    That looks good to me. @Aerzas please can you test?

  • Status changed to Needs work 11 months ago
  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland aerzas

    Thank you for the updated code @viren18febS .

    Unfortunately, it doesn't seem to fix my issue. The langcode is correctly set on the address but it is still the current langcode that it is used by Mailer::doSend. In the context of a legacy email, the __disable_customize__ parameter is set and the langcode processing in the Mailer::doSend method is ended early intentionally, no address is parsed. The address langcode is correct but not the email langcode.

    We could prevent the setting of the __disable_customize__ parameter in LegacyEmailBuilder::createParams, but then the account will also be updated/processed in Mailer::doSend which may have unwanted side effects.

    We could otherwise split the disabling parameter into two: __disable_customize_langcode__ and __disable_customize_account__. This would offer a fine-grained way of handling overrides but will require additional conditions in the process loop.

    Or we could consider that __disable_customize__ only excludes account customization and still gather the langcode from the to addresses.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom adamps

    Good point, thanks @Aerzas. How about this?

    - LegacyEmailBuilder creates the To address with the current langcode and also current account. Add an extra param to parseAddress.
    - Remove all code for __disable_customize__

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium yorder.be

    Has there been any progress on this issue?
    Seems quite the priority since this affects all Core user mails.
    Or is there another workaround to be able to send the mails in the correct language?

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland aerzas

    @yorder.be The patch I proposed fixes the issue in the meanwhile.

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland aerzas

    @AdamPS Thank you for your feedback, I'll work on a new MR as soon as I can.

Production build 0.71.5 2024