Module: I18n::Backend::Chain::Implementation

Includes:
Base
Included in:
I18n::Backend::Chain
Defined in:
lib/i18n/backend/chain.rb

Constant Summary

Constants included from Transliterator

Transliterator::DEFAULT_REPLACEMENT_CHAR

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base

#load_translations

Methods included from Transliterator

get, #transliterate

Instance Attribute Details

#backendsObject

Returns the value of attribute backends.



21
22
23
# File 'lib/i18n/backend/chain.rb', line 21

def backends
  @backends
end

Instance Method Details

#available_localesObject



35
36
37
# File 'lib/i18n/backend/chain.rb', line 35

def available_locales
  backends.map { |backend| backend.available_locales }.flatten.uniq
end

#initialize(*backends) ⇒ Object



23
24
25
# File 'lib/i18n/backend/chain.rb', line 23

def initialize(*backends)
  self.backends = backends
end

#localize(locale, object, format = :default, options = {}) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/i18n/backend/chain.rb', line 61

def localize(locale, object, format = :default, options = {})
  backends.each do |backend|
    begin
      result = backend.localize(locale, object, format, options) and return result
    rescue MissingTranslationData
    end
  end
  raise(I18n::MissingTranslationData.new(locale, format, options))
end

#reload!Object



27
28
29
# File 'lib/i18n/backend/chain.rb', line 27

def reload!
  backends.each { |backend| backend.reload! }
end

#store_translations(locale, data, options = {}) ⇒ Object



31
32
33
# File 'lib/i18n/backend/chain.rb', line 31

def store_translations(locale, data, options = {})
  backends.first.store_translations(locale, data, options)
end

#translate(locale, key, default_options = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/i18n/backend/chain.rb', line 39

def translate(locale, key, default_options = {})
  namespace = nil
  options = default_options.except(:default)

  backends.each do |backend|
    begin
      options = default_options if backend == backends.last
      translation = backend.translate(locale, key, options)
      if namespace_lookup?(translation, options)
        namespace ||= {}
        namespace.merge!(translation)
      elsif !translation.nil?
        return translation
      end
    rescue MissingTranslationData
    end
  end

  return namespace if namespace
  raise(I18n::MissingTranslationData.new(locale, key, options))
end