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

### Home Classes Methods

### In Files

- lib/i18n/backend/chain.rb

### Methods

- ::new
- #available_locales
- #exists?
- #localize
- #namespace_lookup?
- #reload!
- #store_translations
- #translate

### Included Modules

- I18n::Backend::Base

### Class/Module Index

Quicksearch

- I18n
- I18n::ArgumentError
- I18n::Backend
- I18n::Backend::Base
- I18n::Backend::Cache
- I18n::Backend::Cascade
- I18n::Backend::Chain
- I18n::Backend::Chain::Implementation
- I18n::Backend::Fallbacks
- I18n::Backend::Flatten
- I18n::Backend::Gettext
- I18n::Backend::Gettext::PoData
- I18n::Backend::InterpolationCompiler
- I18n::Backend::InterpolationCompiler::Compiler
- I18n::Backend::KeyValue
- I18n::Backend::KeyValue::Implementation
- I18n::Backend::Memoize
- I18n::Backend::Metadata
- I18n::Backend::Pluralization
- I18n::Backend::Simple
- I18n::Backend::Simple::Implementation
- I18n::Config
- I18n::ExceptionHandler
- I18n::Gettext
- I18n::Gettext::Helpers
- I18n::InvalidLocale
- I18n::InvalidLocaleData
- I18n::InvalidPluralizationData
- I18n::Locale
- I18n::Locale::Fallbacks
- I18n::Locale::Tag
- I18n::Locale::Tag::Parents
- I18n::Locale::Tag::Rfc4646
- I18n::Locale::Tag::Rfc4646::Parser
- I18n::Locale::Tag::Simple
- I18n::MissingInterpolationArgument
- I18n::MissingTranslation
- I18n::MissingTranslation::Base
- I18n::MissingTranslationData
- I18n::ReservedInterpolationKey
- I18n::Tests
- I18n::Tests::Basics
- I18n::Tests::Defaults
- I18n::Tests::Link
- I18n::Tests::Localization
- I18n::Tests::Lookup
- I18n::Tests::Pluralization
- I18n::Tests::Procs
- I18n::UnknownFileType
- GetText
- GetText::PoParser
- Hash
- Kernel

No matching classes.

# I18n::Backend::Chain::Implementation

### Attributes

backends[RW]

### Public Class Methods

new(*backends) click to toggle source

    # File lib/i18n/backend/chain.rb, line 23
    def initialize(*backends)
      self.backends = backends
    end

### Public Instance Methods

available_locales() click to toggle source

    # File lib/i18n/backend/chain.rb, line 35
    def available_locales
      backends.map { |backend| backend.available_locales }.flatten.uniq
    end

exists?(locale, key) click to toggle source

    # File lib/i18n/backend/chain.rb, line 59
    def exists?(locale, key)
      backends.any? do |backend|
        backend.exists?(locale, key)
      end
    end

localize(locale, object, format = :default, options = {}) click to toggle source

    # File lib/i18n/backend/chain.rb, line 65
    def localize(locale, object, format = :default, options = {})
      backends.each do |backend|
        catch(:exception) do
          result = backend.localize(locale, object, format, options) and return result
        end
      end
      throw(:exception, I18n::MissingTranslation.new(locale, format, options))
    end

reload!() click to toggle source

    # File lib/i18n/backend/chain.rb, line 27
    def reload!
      backends.each { |backend| backend.reload! }
    end

store_translations(locale, data, options = {}) click to toggle source

    # 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 = {}) click to toggle source

    # 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|
        catch(:exception) do
          options = default_options if backend == backends.last
          translation = backend.translate(locale, key, options)
          if namespace_lookup?(translation, options)
            namespace = _deep_merge(translation, namespace || {})
          elsif !translation.nil?
            return translation
          end
        end
      end

      return namespace if namespace
      throw(:exception, I18n::MissingTranslation.new(locale, key, options))
    end

### Protected Instance Methods

namespace_lookup?(result, options) click to toggle source

    # File lib/i18n/backend/chain.rb, line 75
    def namespace_lookup?(result, options)
      result.is_a?(Hash) && !options.has_key?(:count)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.