-
-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alert emails sent to the user always use the site's default language #5164
Comments
The fix might be something as simple as enclosing the affected code block in a Example from: # Tell the requester that a new response has arrived
def new_response(info_request, incoming_message)
@incoming_message, @info_request = incoming_message, info_request
set_reply_to_headers(info_request.user)
set_auto_generated_headers
+ AlaveteliLocalization.with_locale(info_request.user.locale) do
mail(
:from => contact_for_user(info_request.user),
:to => info_request.user.name_and_email,
:subject => _("New response to your FOI request - {{request_title}}",
:request_title => info_request.title.html_safe),
:charset => "UTF-8"
)
+ end
end (Would need tests to show what happens with the default language used, the user having something other than the default set (off the top of my head, 'es' should be available in the test suite) - including nil and an invalid/unavailable choice - and for code and tests to be repeated for all the cases where this could happen.) |
We also have |
Effectively that is using It's automatically populated via |
Oh yes, durr! Yeah, it looks like what you suggest sounds like how we'd want to approach fixing this – send the email in the locale the user last used, which we're storing anyway. |
Presumed without testing to also affect (but may not be limited to):
(Although we could probably call the request alerts feature complete by adding locale awareness to all the above, and dealing with notification mailers etc separately) |
Since 2019, the method
Then all calls to
There are about 25 uses of Would a PR along these lines be accepted? |
@andersjl, @mattiasaxell ah yes I see the issues here. Moving the subject attribute into a block so it can be parsed as the locale set by the user seems like it would work. Alternatively I think we could pass an optional And in diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb
index c8cd1469f..2261efe00 100644
--- a/app/mailers/application_mailer.rb
+++ b/app/mailers/application_mailer.rb
@@ -45,7 +45,7 @@ def mail_user(user, subject:, **opts)
set_auto_generated_headers
default_opts = {
- subject: subject
+ subject: subject.respond_to?(:call) ? subject.call : subject
}
default_opts.merge!(opts)
mail(default_opts) If it's just the subject attribute which needs to be localised I would prefer using a |
@gbp I see your point. More obvious to the reader. A drawback would possibly be that a future contributor may by mistake localise the subject before calling I will check the |
@andersjl yep good point, happy to require the subject attribute to always be a proc. |
Issue mysociety#5164 PR candidate Change ApplicationMailer#mail_user to localize its subject: arg using the locale of the user arg. This requires the subject: arg to be a proc. All calls to mail_user are changed accordingly.
This is desirable, but unlikely to be worked on in the next 12 months so closing for now. |
I have an almost finished PR solving this. Actually, if it were not for a severe migrain this morning I would have sent it today. |
@andersjl sorry, this wasn't meant to be closed. We would welcome the contribution. |
If the user made their request in the non-default language of the site (e.g. "Swedish" (
locale: 'sv'
)), as the message-generating code does not get a locale passed in from a session variable, it uses the default language to generate the message.Sample
general.yml
config (excerpt):User browses site, selects "Swedish" and makes request,
AlavateliLocalization.locale
issv
and the request is sent in Swedish.The authority replies. The code that runs to send the email does not have the user's session context and uses the default locale of
en
; the email alert to the user is generated and sent in English.The text was updated successfully, but these errors were encountered: