Module: SmoothOperator::Translation::HelperMethods

Extended by:
HelperMethods
Included in:
HelperMethods
Defined in:
lib/smooth_operator/translation.rb

Instance Method Summary collapse

Instance Method Details

#translate(namespace = '', options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/smooth_operator/translation.rb', line 15

def translate(namespace = '', options = {})
  no_translation = "-- no translation --"

  defaults = ["smooth_operator.#{namespace}".to_sym]
  defaults << "activerecord.#{namespace}".to_sym
  defaults << options[:default] if options[:default]
  defaults.flatten!
  defaults << no_translation

  options = { count: 1, default: defaults }
    .merge!(options.except(:default))

  I18n.translate(defaults.shift, options)
end