Module: I18nAutoScoping::BackendExtension

Defined in:
lib/i18n_auto_scoping.rb

Class Method Summary collapse

Class Method Details

.extended(k) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/i18n_auto_scoping.rb', line 40

def self.extended(k)
  k.class_eval do
    alias_method :i18n_auto_scoping_translate, :translate
    
    # Override translate method in order to set autoscoping
    def translate(locale, key, options = {})
      # Set the default scope if needed
      if !options.has_key?(:scope) or options[:scope] == :autoscoping
        options[:scope] = I18n::Scope.default            
      end
      
      begin
        result = i18n_auto_scoping_translate(locale, key, options)  
      rescue I18n::MissingTranslationData
        options.delete :scope
        result = i18n_auto_scoping_translate(locale, key, options)
      end
      result
    end
  end
end