[openstreetmap/openstreetmap-website] Mailer refactoring (#2993)

Andy Allan notifications at github.com
Wed Dec 2 16:06:28 UTC 2020


This PR contains some translation-related refactoring for the user_mailer.

It took me two attempts to get this right, since there's some subtleties about how the `_html` translations interact with plain text mail templates, and so I had to revisit and refactor some (unsubmitted) work that was done last week when I realised what was going on. But I've added a test that would have caught my mistake earlier.

In short, `_html` translations take the translation options (e.g. something like `t(".foo", :username => "Jack & Jill")`, html_escapes the options, interpolates them into the translation, and returns the whole thing as a SafeBuffer to avoid further html_escaping in the template. Putting that straight into an html template is fine, since it a) is already a safebuffer and b) is already escaped. But for plain text templates, we don't want any html_escaping of the input options, so we have to avoid using `_html` translation keys. Hence the duplication between the `_html` and non-`_html` keys.
You can view, comment on, or merge this pull request online at:

  https://github.com/openstreetmap/openstreetmap-website/pull/2993

-- Commit Summary --

  * Use rails t helper to allow relative translation keys in email subjects
  * Rename subject translation key, for consistency
  * Remove duplicate translation strings, and use short form translation lookups
  * Avoid calling raw in plain text email templates
  * Add a test for i18n interpolation into plain and html parts
  * Avoid using raw in html mailer views

-- File Changes --

    M app/mailers/user_mailer.rb (26)
    M app/views/user_mailer/changeset_comment_notification.html.erb (10)
    M app/views/user_mailer/diary_comment_notification.html.erb (10)
    M app/views/user_mailer/diary_comment_notification.text.erb (2)
    M app/views/user_mailer/email_confirm.html.erb (6)
    M app/views/user_mailer/email_confirm.text.erb (6)
    M app/views/user_mailer/friendship_notification.html.erb (4)
    M app/views/user_mailer/lost_password.html.erb (6)
    M app/views/user_mailer/lost_password.text.erb (6)
    M app/views/user_mailer/message_notification.html.erb (6)
    M app/views/user_mailer/message_notification.text.erb (8)
    M app/views/user_mailer/note_comment_notification.html.erb (6)
    M config/locales/en.yml (30)
    M test/mailers/user_mailer_test.rb (9)

-- Patch Links --

https://github.com/openstreetmap/openstreetmap-website/pull/2993.patch
https://github.com/openstreetmap/openstreetmap-website/pull/2993.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/2993
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20201202/2a1093f0/attachment.htm>


More information about the rails-dev mailing list