Responsibility:
- store data threadsave - provide error messages when repositories are unconfigured - accept/reject locales that are set by the user
# File lib/fast_gettext/storage.rb, line 28 def available_locales locales = Thread.current[:fast_gettext_available_locales] || default_available_locales return unless locales locales.map{|s|s.to_s} end
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 130 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
# File lib/fast_gettext/storage.rb, line 63 def cache Thread.current[:fast_gettext_cache] ||= cache_class.new end
# File lib/fast_gettext/storage.rb, line 86 def cached_find(key) cache.fetch(key) { current_repository[key] } end
# File lib/fast_gettext/storage.rb, line 90 def cached_plural_find(*keys) key = '||||' + keys * '||||' cache.fetch(key) { current_repository.plural(*keys) } end
# File lib/fast_gettext/storage.rb, line 78 def current_repository translation_repositories[text_domain] || raise(NoTextDomainConfigured) end
# File lib/fast_gettext/storage.rb, line 122 def default_locale @@default_locale end
# File lib/fast_gettext/storage.rb, line 117 def default_locale=(new_locale) @@default_locale = best_locale_in(new_locale) switch_cache end
# File lib/fast_gettext/storage.rb, line 95 def expire_cache_for(key) cache.delete(key) end
# File lib/fast_gettext/storage.rb, line 82 def key_exist?(key) !!(cached_find key) end
# File lib/fast_gettext/storage.rb, line 99 def locale _locale || ( default_locale || (available_locales||[]).first || 'en' ) end
# File lib/fast_gettext/storage.rb, line 103 def locale=(new_locale) set_locale(new_locale) end
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 59 def pluralisation_rule Thread.current[:fast_gettext_pluralisation_rule] || current_repository.pluralisation_rule || lambda{|i| i!=1} end
# File lib/fast_gettext/storage.rb, line 67 def reload! cache.reload! translation_repositories.values.each(&:reload) end
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 110 def set_locale(new_locale) new_locale = best_locale_in(new_locale) self._locale = new_locale locale end
turn off translation if none was defined to disable all resulting errors
# File lib/fast_gettext/storage.rb, line 140 def silence_errors require 'fast_gettext/translation_repository/base' translation_repositories[text_domain] ||= TranslationRepository::Base.new('x', :path => 'locale') end
Generated with the Darkfish Rdoc Generator 2.