Module: I18n::Backend::Cascade

Defined in:
lib/i18n/backend/cascade.rb

Instance Method Summary (collapse)

Instance Method Details

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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/i18n/backend/cascade.rb', line 34

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

  cascade   = { :step => 1 } unless cascade.is_a?(Hash)
  step      = cascade[:step]   || 1
  offset    = cascade[:offset] || 1
  separator = options[:separator] || I18n.default_separator
  skip_root = cascade.has_key?(:skip_root) ? cascade[:skip_root] : true

  scope = I18n.normalize_keys(nil, key, scope, separator)
  key   = (scope.slice!(-offset, offset) || []).join(separator)

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