Module: RailsErrorDashboard::Translation

Overview

Translation for code that is not a view.

I18nHelper#red_t is a view helper: it html-escapes its output, because that is what a template needs. Controllers and commands produce flash messages and result strings that Rails escapes when the view renders them, so escaping here would double-escape every apostrophe.

Both paths resolve the locale the same way — Current.locale_or_default — so a flash message set during a request renders in the same locale as the page that shows it.

Like everything else in the i18n path, these never raise. A controller cannot be the place a translation lookup takes down the dashboard.

Instance Method Summary collapse

Instance Method Details

#red_localeString

Returns a locale RED ships.

Returns:

  • (String)

    a locale RED ships



33
34
35
36
37
# File 'lib/rails_error_dashboard/translation.rb', line 33

def red_locale
  Current.locale_or_default
rescue StandardError
  I18nStore::DEFAULT_LOCALE
end

#red_t(key, **options) ⇒ String

Returns never nil, never raises, never html-escaped.

Parameters:

  • key (String, Symbol)

    e.g. "red.flash.issue.created"

Returns:

  • (String)

    never nil, never raises, never html-escaped



20
21
22
23
24
# File 'lib/rails_error_dashboard/translation.rb', line 20

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

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

Pluralized translation. Selects the form from count using the locale's CLDR rules rather than an English binary plural.



28
29
30
# File 'lib/rails_error_dashboard/translation.rb', line 28

def red_tp(key, count:, **options)
  red_t(key, count: count, **options)
end