Module: RailsErrorDashboard::Translation
- Included in:
- ApplicationController, Commands::BatchDeleteErrors, Commands::BatchMuteErrors, Commands::BatchResolveErrors, Commands::BatchUnmuteErrors, Commands::CreateIssue, Commands::LinkExistingIssue
- Defined in:
- lib/rails_error_dashboard/translation.rb
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
-
#red_locale ⇒ String
A locale RED ships.
-
#red_t(key, **options) ⇒ String
Never nil, never raises, never html-escaped.
-
#red_tp(key, count:, **options) ⇒ Object
Pluralized translation.
Instance Method Details
#red_locale ⇒ String
Returns 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.
20 21 22 23 24 |
# File 'lib/rails_error_dashboard/translation.rb', line 20 def red_t(key, **) I18nStore.translate(key, locale: red_locale, **) 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:, **) red_t(key, count: count, **) end |