Skip to content

Send notification emails in the recipient's preferred language#431

Open
Copilot wants to merge 5 commits intomasterfrom
copilot/fix-notification-email-language
Open

Send notification emails in the recipient's preferred language#431
Copilot wants to merge 5 commits intomasterfrom
copilot/fix-notification-email-language

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 4, 2026

  • Explore codebase to understand notification and language systems
  • Modify _issue_watchers() to return email + language per recipient
  • Add _set_language() helper to temporarily set language per recipient
  • Update all notification methods to render per-recipient in their language
  • Fix _set_language() return type to ?string and remove (string) cast so a null LANGUAGE is restored as null, not ""
Original prompt

This section details on the original issue you should resolve

<issue_title>Notification emails are not translated</issue_title>
<issue_description>The notifications should use the user's language setting, followed by the global language setting to select translations for notification email components.
</issue_description>

<agent_instructions>Ensure notification emails are sent in the recipient user's language, if the user has a language manually set.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@Alanaktion Notification email language currently matches the sender's language, not the recipient's. We need to cleanly change the app language to match the user's preference when it's set. This isn't perfect, as many users will be using an English-language site, but let their browser determine the display language automatically when browsing, which we don't keep track of when that user isn't present. The best we can do with the current data is send emails following the user's manual setting if there is one, and hope the default on the site works if it's not set.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: Alanaktion <236490+Alanaktion@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix notification emails not being translated correctly Send notification emails in the recipient's preferred language Mar 4, 2026
@Alanaktion Alanaktion marked this pull request as ready for review March 4, 2026 03:22
Copilot AI review requested due to automatic review settings March 4, 2026 03:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes notification email localization by switching template rendering to run per-recipient using each recipient’s stored language preference, instead of using the sender/current session language.

Changes:

  • Updated issue notification senders to render templates inside the per-recipient loop and temporarily switch LANGUAGE for each recipient.
  • Extended _issue_watchers() to return email + language pairs and adjusted related SQL queries (including group membership lookup).
  • Added _set_language(?string $language): string helper and applied it to non-issue notifications (user_reset, user_due_issues).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +425 to +429
$original = (string) $f3->get("LANGUAGE");
if ($language) {
$f3->set("LANGUAGE", $language);
}
return $original;
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_set_language() always casts the previous LANGUAGE to a string and callers always restore via set("LANGUAGE", $previous). If LANGUAGE was previously unset/null, this forces it to "" on restore, which can change how locale fallback behaves. Consider tracking whether LANGUAGE originally existed and using clear("LANGUAGE") (or not restoring) when it didn’t.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

If the original value was null, it should be null when changing back. Don't skip restoring.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 348ff36. Changed the return type of _set_language() from string to ?string and removed the (string) cast when reading the original value, so a null LANGUAGE is preserved and restored as null rather than "".

Alanaktion and others added 2 commits March 4, 2026 09:24
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Alanaktion <236490+Alanaktion@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notification emails are not translated

3 participants