Module: I18n::Backend::Chain::Implementation
Constant Summary
Constants included from Transliterator
Transliterator::DEFAULT_REPLACEMENT_CHAR
Instance Attribute Summary collapse
-
#backends ⇒ Object
Returns the value of attribute backends.
Instance Method Summary collapse
- #available_locales ⇒ Object
- #eager_load! ⇒ Object
- #exists?(locale, key, options = EMPTY_HASH) ⇒ Boolean
- #initialize(*backends) ⇒ Object
- #initialized? ⇒ Boolean
- #localize(locale, object, format = :default, options = EMPTY_HASH) ⇒ Object
- #reload! ⇒ Object
- #store_translations(locale, data, options = EMPTY_HASH) ⇒ Object
- #translate(locale, key, default_options = EMPTY_HASH) ⇒ Object
Methods included from Base
Methods included from Transliterator
Instance Attribute Details
#backends ⇒ Object
Returns the value of attribute backends.
25 26 27 |
# File 'lib/i18n/backend/chain.rb', line 25 def backends @backends end |
Instance Method Details
#available_locales ⇒ Object
52 53 54 |
# File 'lib/i18n/backend/chain.rb', line 52 def available_locales backends.map { |backend| backend.available_locales }.flatten.uniq end |
#eager_load! ⇒ Object
44 45 46 |
# File 'lib/i18n/backend/chain.rb', line 44 def eager_load! backends.each { |backend| backend.eager_load! } end |
#exists?(locale, key, options = EMPTY_HASH) ⇒ Boolean
76 77 78 79 80 |
# File 'lib/i18n/backend/chain.rb', line 76 def exists?(locale, key, = EMPTY_HASH) backends.any? do |backend| backend.exists?(locale, key, ) end end |
#initialize(*backends) ⇒ Object
27 28 29 |
# File 'lib/i18n/backend/chain.rb', line 27 def initialize(*backends) self.backends = backends end |
#initialized? ⇒ Boolean
31 32 33 34 35 36 37 38 |
# File 'lib/i18n/backend/chain.rb', line 31 def initialized? backends.all? do |backend| backend.instance_eval do return false unless initialized? end end true end |
#localize(locale, object, format = :default, options = EMPTY_HASH) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/i18n/backend/chain.rb', line 82 def localize(locale, object, format = :default, = EMPTY_HASH) backends.each do |backend| catch(:exception) do result = backend.localize(locale, object, format, ) and return result end end throw(:exception, I18n::MissingTranslation.new(locale, format, )) end |
#reload! ⇒ Object
40 41 42 |
# File 'lib/i18n/backend/chain.rb', line 40 def reload! backends.each { |backend| backend.reload! } end |
#store_translations(locale, data, options = EMPTY_HASH) ⇒ Object
48 49 50 |
# File 'lib/i18n/backend/chain.rb', line 48 def store_translations(locale, data, = EMPTY_HASH) backends.first.store_translations(locale, data, ) end |
#translate(locale, key, default_options = EMPTY_HASH) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/i18n/backend/chain.rb', line 56 def translate(locale, key, = EMPTY_HASH) namespace = nil = Utils.except(, :default) backends.each do |backend| catch(:exception) do = if backend == backends.last translation = backend.translate(locale, key, ) if namespace_lookup?(translation, ) namespace = _deep_merge(translation, namespace || {}) elsif !translation.nil? || (.key?(:default) && [:default].nil?) return translation end end end return namespace if namespace throw(:exception, I18n::MissingTranslation.new(locale, key, )) end |