Module: RailsErrorDashboard::MailerI18nHelper

Includes:
I18nHelper
Defined in:
app/helpers/rails_error_dashboard/mailer_i18n_helper.rb

Overview

Translation entry points for mailer templates.

Mailers need two things the dashboard's I18nHelper does not provide.

  1. AN UNESCAPED VARIANT, for the .text.erb parts.

    red_t html-escapes, which is right for a web page and wrong for a plain text email: a French string would arrive in the recipient's mail client as "Impossible d'accéder". The .html.erb parts still use red_t. The split mirrors I18nHelper vs. Translation elsewhere in the gem — the test is where the string lands, not what it looks like.

  2. A DATE FORMATTER THAT DOES NOT DEPEND ON JAVASCRIPT.

    ApplicationHelper#local_time renders a that the dashboard's JS re-renders in the reader's timezone and locale. Email has no JS, so a mailer must produce finished text server-side.

    Ruby's strftime is not locale-aware: %B is "August" whatever RED's locale is. P3-T2 already put localized month, day and meridian names in red.js.* for the browser's formatDateTime(); red_mail_time substitutes the same vocabulary before handing the rest to strftime, so an email and the dashboard render a date identically.

Instance Method Summary collapse

Methods included from I18nHelper

#red_chart_date, #red_js_t, #red_js_tp, #red_js_translations, #red_locale, #red_t, #red_time_format, #red_tp

Instance Method Details

#red_mail_t(key, **options) ⇒ String

Translate for a text/plain mailer part. Same lookup as red_t, no HTML escaping. Use red_t in the .html.erb parts.

Returns:

  • (String)

    never nil, never raises



40
41
42
43
44
# File 'app/helpers/rails_error_dashboard/mailer_i18n_helper.rb', line 40

def red_mail_t(key, **options)
  I18nStore.translate(key, locale: red_locale, **options)
rescue StandardError
  ""
end

#red_mail_time(time, format: :full) ⇒ String

A finished, localized timestamp for an email.

Parameters:

  • time (Time, nil)
  • format (Symbol) (defaults to: :full)

    a preset from red.time.formats

Returns:

  • (String)

    "" for nil — a mailer must never render "undefined", and must never raise on the way to a notification



57
58
59
60
61
62
63
64
65
66
67
# File 'app/helpers/rails_error_dashboard/mailer_i18n_helper.rb', line 57

def red_mail_time(time, format: :full)
  return "" if time.nil?

  utc = time.respond_to?(:utc) ? time.utc : time
  pattern = red_time_format(format)

  "#{Services::LocalizedTimeFormatter.call(utc, pattern: pattern, locale: red_locale)} UTC"
rescue StandardError
  # A timestamp is worth losing; the notification is not.
  time.to_s
end

#red_mail_tp(key, count:, **options) ⇒ Object

Pluralized variant of red_mail_t.



47
48
49
# File 'app/helpers/rails_error_dashboard/mailer_i18n_helper.rb', line 47

def red_mail_tp(key, count:, **options)
  red_mail_t(key, count: count, **options)
end