Module: RailsStuff::Helpers::Translation

Included in:
All
Defined in:
lib/rails_stuff/helpers/translation.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.i18n_raiseObject



5
6
7
# File 'lib/rails_stuff/helpers/translation.rb', line 5

def i18n_raise
  @i18n_raise ||= defined?(Rails) && ActionView::Base.raise_on_missing_translations
end

Instance Method Details

#translate_action(action) ⇒ Object

Translates & caches actions within ‘helpers.actions` scope.



13
14
15
16
17
18
# File 'lib/rails_stuff/helpers/translation.rb', line 13

def translate_action(action)
  @translate_action ||= Hash.new do |h, key|
    h[key] = I18n.t("helpers.actions.#{key}", raise: Translation.i18n_raise)
  end
  @translate_action[action]
end

#translate_confirmation(action) ⇒ Object

Translates & caches confirmations within ‘helpers.confirmations` scope.



21
22
23
24
25
26
27
28
29
# File 'lib/rails_stuff/helpers/translation.rb', line 21

def translate_confirmation(action)
  @translate_confirmation ||= Hash.new do |h, key|
    h[key] = I18n.t("helpers.confirmations.#{key}",
      default: [:'helpers.confirm'],
      raise: Translation.i18n_raise,
    )
  end
  @translate_confirmation[action]
end

#yes_no(val) ⇒ Object

Translates boolean values.



32
33
34
35
36
37
# File 'lib/rails_stuff/helpers/translation.rb', line 32

def yes_no(val)
  @translate_yes_no ||= Hash.new do |h, key|
    h[key] = I18n.t("helpers.yes_no.#{key}", raise: Translation.i18n_raise)
  end
  @translate_yes_no[val.to_s]
end