Module: FastGettext::Storage

### Home Classes Methods

### In Files

- lib/fast_gettext/storage.rb

### Namespace

- CLASS FastGettext::Storage::NoTextDomainConfigured

### Methods

- #available_locales
- #best_locale_in
- #cached_find
- #cached_plural_find
- #caches
- #current_cache
- #current_cache=
- #current_repository
- #default_available_locales
- #default_available_locales=
- #default_locale
- #default_locale=
- #default_text_domain
- #default_text_domain=
- #expire_cache_for
- #key_exist?
- #locale
- #locale=
- #pluralisation_rule
- #reload!
- #set_locale
- #silence_errors
- #text_domain
- #translation_repositories

### Class/Module Index

Quicksearch

- FastGettext
- FastGettext::GetText
- FastGettext::GetText::MOFile
- FastGettext::GetText::MOFile::HeaderRev1
- FastGettext::GetText::MOFile::InvalidFormat
- FastGettext::GetText::PoParser
- FastGettext::MoFile
- FastGettext::PoFile
- FastGettext::Storage
- FastGettext::Storage::NoTextDomainConfigured
- FastGettext::Translation
- FastGettext::TranslationMultidomain
- FastGettext::TranslationRepository
- FastGettext::TranslationRepository::Base
- FastGettext::TranslationRepository::Chain
- FastGettext::TranslationRepository::Db
- FastGettext::TranslationRepository::Logger
- FastGettext::TranslationRepository::Mo
- FastGettext::TranslationRepository::Po
- FastGettext::TranslationRepository::Yaml
- String
- TranslationKey
- TranslationText

No matching classes.

# FastGettext::Storage

Responsibility:

    - store data threadsave
    - provide error messages when repositories are unconfigured
    - accept/reject locales that are set by the user

### Public Instance Methods

available_locales() click to toggle source

    # File lib/fast_gettext/storage.rb, line 26
    def available_locales
      locales = Thread.current[:fast_gettext_available_locales] || default_available_locales
      return unless locales
      locales.map{|s|s.to_s}
    end

best_locale_in(locales) click to toggle source

Opera: de-DE,de;q=0.9,en;q=0.8 Firefox de-de,de;q=0.8,en-us;q=0.5,en;q=0.3 IE6/7 de nil if nothing matches

    # File lib/fast_gettext/storage.rb, line 154
    def best_locale_in(locales)
      formatted_sorted_locales(locales).each do |candidate|
        return candidate if not available_locales
        return candidate if available_locales.include?(candidate)
        return candidate[0..1] if available_locales.include?(candidate[0..1])#available locales include a langauge
      end
      return nil#nothing found im sorry :P
    end

cached_find(key) click to toggle source

    # File lib/fast_gettext/storage.rb, line 100
    def cached_find(key)
      translation = current_cache[key]
      if translation.nil? # uncached
        current_cache[key] = current_repository[key] || false
      else
        translation
      end
    end

cached_plural_find(*keys) click to toggle source

    # File lib/fast_gettext/storage.rb, line 109
    def cached_plural_find(*keys)
      key = '||||' + keys * '||||'
      translation = current_cache[key]
      if translation.nil? # uncached
        current_cache[key] = current_repository.plural(*keys) || false
      else
        translation
      end
    end

caches() click to toggle source

    # File lib/fast_gettext/storage.rb, line 88
    def caches
      @@caches
    end

current_cache() click to toggle source

    # File lib/fast_gettext/storage.rb, line 66
    def current_cache
      Thread.current[:fast_gettext_current_cache] || {}
    end

current_cache=(cache) click to toggle source

    # File lib/fast_gettext/storage.rb, line 70
    def current_cache=(cache)
      Thread.current[:fast_gettext_current_cache] = cache
    end

current_repository() click to toggle source

    # File lib/fast_gettext/storage.rb, line 92
    def current_repository
      translation_repositories[text_domain] || raise(NoTextDomainConfigured)
    end

default_available_locales() click to toggle source

    # File lib/fast_gettext/storage.rb, line 39
    def default_available_locales
      @@default_available_locales
    end

default_available_locales=(avail_locales) click to toggle source

    # File lib/fast_gettext/storage.rb, line 34
    def default_available_locales=(avail_locales)
      @@default_available_locales = avail_locales
      update_current_cache
    end

default_locale() click to toggle source

    # File lib/fast_gettext/storage.rb, line 146
    def default_locale
      @@default_locale
    end

default_locale=(new_locale) click to toggle source

    # File lib/fast_gettext/storage.rb, line 141
    def default_locale=(new_locale)
      @@default_locale = best_locale_in(new_locale)
      update_current_cache
    end

default_text_domain() click to toggle source

    # File lib/fast_gettext/storage.rb, line 55
    def default_text_domain
      @@default_text_domain
    end

default_text_domain=(domain) click to toggle source

    # File lib/fast_gettext/storage.rb, line 50
    def default_text_domain=(domain)
      @@default_text_domain = domain
      update_current_cache
    end

expire_cache_for(key) click to toggle source

    # File lib/fast_gettext/storage.rb, line 119
    def expire_cache_for(key)
      current_cache.delete(key)
    end

key_exist?(key) click to toggle source

    # File lib/fast_gettext/storage.rb, line 96
    def key_exist?(key)
      !!(cached_find key)
    end

locale() click to toggle source

    # File lib/fast_gettext/storage.rb, line 123
    def locale
      _locale || ( default_locale || (available_locales||[]).first || 'en' )
    end

locale=(new_locale) click to toggle source

    # File lib/fast_gettext/storage.rb, line 127
    def locale=(new_locale)
      set_locale(new_locale)
    end

pluralisation_rule() click to toggle source

if overwritten by user( FastGettext.pluralisation_rule = xxx) use it, otherwise fall back to repo or to default lambda

    # File lib/fast_gettext/storage.rb, line 62
    def pluralisation_rule
      Thread.current[:fast_gettext_pluralisation_rule] ||  current_repository.pluralisation_rule || lambda{|i| i!=1}
    end

reload!() click to toggle source

    # File lib/fast_gettext/storage.rb, line 74
    def reload!
      self.current_cache = {}
      translation_repositories.values.each(&:reload)
    end

set_locale(new_locale) click to toggle source

for chaining: puts set_locale('xx') == 'xx' ? 'applied' : 'rejected' returns the current locale, not the one that was supplied like locale=(), whoes behavior cannot be changed

    # File lib/fast_gettext/storage.rb, line 134
    def set_locale(new_locale)
      new_locale = best_locale_in(new_locale)
      self._locale = new_locale
      locale
    end

silence_errors() click to toggle source

turn off translation if none was defined to disable all resulting errors

    # File lib/fast_gettext/storage.rb, line 164
    def silence_errors
      require 'fast_gettext/translation_repository/base'
      translation_repositories[text_domain] ||= TranslationRepository::Base.new('x', :path => 'locale')
    end

text_domain() click to toggle source

    # File lib/fast_gettext/storage.rb, line 44
    def text_domain
      Thread.current[:fast_gettext_text_domain] || default_text_domain
    end

translation_repositories() click to toggle source

    # File lib/fast_gettext/storage.rb, line 81
    def translation_repositories
      @@translation_repositories
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.