Module: I18n::Backend::Cascade

Defined in:
lib/active_support/vendor/i18n-0.4.1/i18n/backend/cascade.rb

Instance Method Summary collapse

Instance Method Details

#lookup(locale, key, scope = [], options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/active_support/vendor/i18n-0.4.1/i18n/backend/cascade.rb', line 38

def lookup(locale, key, scope = [], options = {})
  return super unless cascade = options[:cascade]

  separator = options[:separator] || I18n.default_separator
  skip_root = cascade.has_key?(:skip_root) ? cascade[:skip_root] : true
  step      = cascade[:step]

  keys   = I18n.normalize_keys(nil, key, nil, separator)
  offset = options[:cascade][:offset] || keys.length
  scope  = I18n.normalize_keys(nil, nil, scope, separator) + keys
  key    = scope.slice!(-offset, offset).join(separator)

  begin
    result = super
    return result unless result.nil?
  end while !scope.empty? && scope.slice!(-step, step) && (!scope.empty? || !skip_root)
end