module ActiveModel::Translation

Public Instance Methods

t(key, options = {})
Alias for: translate
translate(key, options = {}) click to toggle source

Delegates to I18n#translate but also performs scoping if key starts with a period. So if you call translate(".foo") translation will be searched in I18N_SCOPE.strings.MODEL.foo then the same key for all the ancestors and finally in strings.foo.

# File lib/activemodel_translation/helper.rb, line 11
def translate(key, options = {})
  return I18n.translate(key, options) unless key.to_s.first == '.'

  strings_scope = "#{i18n_scope}.strings"

  defaults = lookup_ancestors.map do |klass|
    :"#{strings_scope}.#{klass.model_name.i18n_key}#{key}"
  end
  defaults << :"strings#{key}"
  defaults << options.delete(:default) if options[:default]

  options[:default] = defaults
  I18n.translate(defaults.shift, options)
end
Also aliased as: t