Module: I18n::Backend::Simple::Implementation

### Home Classes Methods

### In Files

- lib/i18n/backend/simple.rb

### Methods

- #available_locales
- #init_translations
- #initialized?
- #lookup
- #reload!
- #store_translations
- #translations

### 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::Simple::Implementation

### Public Instance Methods

available_locales() click to toggle source

Get available locales from the translations hash

    # File lib/i18n/backend/simple.rb, line 39
    def available_locales
      init_translations unless initialized?
      translations.inject([]) do |locales, (locale, data)|
        locales << locale unless (data.keys - [:i18n]).empty?
        locales
      end
    end

initialized?() click to toggle source

    # File lib/i18n/backend/simple.rb, line 23
    def initialized?
      @initialized ||= false
    end

reload!() click to toggle source

Clean up translations hash and set initialized to false on reload!

    # File lib/i18n/backend/simple.rb, line 48
    def reload!
      @initialized = false
      @translations = nil
      super
    end

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

Stores translations for the given locale in memory. This uses a deep merge for the translations hash, so existing translations will be overwritten by new ones only at the deepest level of the hash.

    # File lib/i18n/backend/simple.rb, line 31
    def store_translations(locale, data, options = {})
      locale = locale.to_sym
      translations[locale] ||= {}
      data = data.deep_symbolize_keys
      translations[locale].deep_merge!(data)
    end

### Protected Instance Methods

init_translations() click to toggle source

    # File lib/i18n/backend/simple.rb, line 56
    def init_translations
      load_translations
      @initialized = true
    end

lookup(locale, key, scope = [], options = {}) click to toggle source

Looks up a translation from the translations hash. Returns nil if eiher key is nil, or locale, scope or key do not exist as a key in the nested translations hash. Splits keys or scopes containing dots into multiple keys, i.e. `currency.format` is regarded the same as `%w(currency format)`.

    # File lib/i18n/backend/simple.rb, line 70
    def lookup(locale, key, scope = [], options = {})
      init_translations unless initialized?
      keys = I18n.normalize_keys(locale, key, scope, options[:separator])

      keys.inject(translations) do |result, _key|
        _key = _key.to_sym
        return nil unless result.is_a?(Hash) && result.has_key?(_key)
        result = result[_key]
        result = resolve(locale, _key, result, options.merge(:scope => nil)) if result.is_a?(Symbol)
        result
      end
    end

translations() click to toggle source

    # File lib/i18n/backend/simple.rb, line 61
    def translations
      @translations ||= {}
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.