Skip to content

[2.x] fix: send transactional emails in recipient's preferred locale - #4627

Merged
imorland merged 1 commit into
2.xfrom
im/email-recipient-locale
May 6, 2026
Merged

[2.x] fix: send transactional emails in recipient's preferred locale#4627
imorland merged 1 commit into
2.xfrom
im/email-recipient-locale

Conversation

@imorland

@imorland imorland commented May 6, 2026

Copy link
Copy Markdown
Member

Summary

  • Translates email subject/body under the recipient's preferred locale (User::getPreference('locale')), falling back to the forum's default_locale.
  • Carries the per-recipient locale through to SendInformationalEmailJob and SendAbandonedExtensionsEmailJob so the wrapper template's greeting / signoff strings render in the same language as subject/body — fixing the mixed-language output described in [2.x] Transactional emails are sent in mixed languages instead of the recipient's preferred locale #4626.
  • Moves abandoned-extensions translation inside the per-admin loop so each admin receives the email in their own locale (was previously translated once outside the loop, so all admins got the same language).
  • Mirrors the existing pattern in NotificationMailer::send().

Fixes #4626

Changes

  • Mail/Job/SendInformationalEmailJob — adds optional ?string $locale (after $views to preserve positional BC); injects TranslatorInterface into handle() and applies locale before send.
  • Mail/Job/SendAbandonedExtensionsEmailJob — same shape.
  • Api/Controller/SendTestMailController — switches to actor's locale, translates, restores previous locale in finally.
  • User/Job/RequestPasswordResetJob — same pattern, recipient = looked-up user.
  • User/EmailConfirmationMailer — same pattern.
  • User/AccountActivationMailerTrait — same pattern (already had User $user in scope).
  • Extension/AbandonedExtensionsFetcher::notifyAdmins() — moves translation inside loop, switches to Flarum's Locale\TranslatorInterface (Symfony's contract doesn't expose setLocale()), wraps loop in try/finally.

Test plan

  • Forum default locale = German (de), admin user preference = English (en). Trigger Send test mail — full email renders in English.
  • Same setup, request a password reset for the admin — full email renders in English.
  • User with no locale preference set — email renders in the forum default locale (German).
  • Two admins with different locale preferences (e.g. one English, one German). Trigger an abandoned-extensions notification — each admin receives the email in their own locale.
  • Verify subscription / reply notification mails (handled by NotificationMailer) are unchanged.
  • PHPUnit suite passes.

Notes

  • Backward compatibility: the new locale parameter on both jobs is optional and trailing, so existing third-party callers (positional or named) continue to work unchanged. When null, behavior is identical to today.
  • All changes target a single bug class — no unrelated cleanup.

Switches translator to the recipient's locale preference (falling back to
the forum default) before translating subject/body, and carries that locale
through to SendInformationalEmailJob and SendAbandonedExtensionsEmailJob so
the wrapper template's greeting/signoff render in the same language.

For abandoned-extensions notifications, moves translation inside the
per-admin loop so each admin receives the email in their own preferred
locale rather than all admins receiving the same language.

Mirrors the existing pattern in NotificationMailer.

Refs #4626
@imorland
imorland requested a review from a team as a code owner May 6, 2026 12:02
@imorland imorland modified the milestone: 2.0.0-rc.2 May 6, 2026
@imorland
imorland merged commit 89d8015 into 2.x May 6, 2026
25 checks passed
@imorland
imorland deleted the im/email-recipient-locale branch May 6, 2026 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[2.x] Transactional emails are sent in mixed languages instead of the recipient's preferred locale

1 participant