lib/rails_ext/i18n_helper.rb in rails-ext-0.2.5 vs lib/rails_ext/i18n_helper.rb in rails-ext-0.2.6

- old
+ new

@@ -23,50 +23,68 @@ } # t() and t_scope() list = [Object, ActionController::Base, ActionView::Base, ActionMailer::Base] list << ActiveRecord::Base if defined?(ActiveRecord) - list.each do |_class| - _class.class_eval do + list.each do |aclass| + aclass.class_eval do # def self.t_scope_value; end # hack, becouse of rails method_missing magic it causes error # def t_scope_value; end # hack, becouse of rails method_missing magic it causes error - - def self.t_scope *scopes - class_inheritable_accessor :t_scope_value unless respond_to? :t_scope_value - self.t_scope_value = scopes.collect{|scope| scope + "_scope"} - end + # + # def self.t_scope *scopes + # class_inheritable_accessor :t_scope_value unless respond_to? :t_scope_value + # self.t_scope_value = scopes.collect{|scope| scope + "_scope"} + # end # finding translation in all class hierarchy - def t message, params = {} - result = nil - - aclass = self.is_a?(Class) ? self : self.class - list = aclass.ancestors - list.unshift self unless self.is_a?(Class) # hack for ActionView and ActionMailer - - list.each do |c| - begin - next unless t_scope = c.respond_to(:t_scope_value) - rescue NameError # hack for rails method_missing magic - next - end - - t_scope.each do |ts| - begin - result = I18n.t "#{ts}.#{message}", params.merge(:raise => true) - rescue I18n::MissingTranslationData - end - break if result - end - - break if result - end - - result ||= I18n.t message, params - result.to_s # Globalize2 uses Translation::Static instead of String + # def t message, params = {} + # # begin + # # p([message, respond_to(:t_scope_value)]) + # # rescue + # # p([self.t_scope_value]) + # # end + # + # result = nil + # + # aclass = self.is_a?(Class) ? self : self.class + # list = aclass.ancestors + # list.unshift self unless self.is_a?(Class) # hack for ActionView and ActionMailer + # + # catch :found do + # list.each do |c| + # t_scope = begin + # c.respond_to(:t_scope_value) + # rescue NameError # hack for rails method_missing magic + # begin + # c.t_scope_value + # rescue NoMethodError + # nil + # end + # end + # + # next unless t_scope + # + # t_scope.each do |ts| + # begin + # result = I18n.t "#{ts}.#{message}", params.merge(:raise => true) + # rescue I18n::MissingTranslationData + # end + # throw :found if result + # end + # end + # end + # + # result ||= I18n.t message, params + # result.to_s # Globalize2 uses Translation::Static instead of String + # end + + def t *args + # Globalize2 uses Translation::Static instead of String + I18n.t(*args).to_s end + end end # ActionController::Base.class_eval do # # Becouse we need to transfer @t_scope also to View @@ -77,18 +95,18 @@ # end # alias_method_chain :initialize, :t_scope # end ActionView::Base.class_eval do - def t_scope_value - controller.class.t_scope_value if controller.class.respond_to? :t_scope_value - end + # def t_scope_value + # controller.class.t_scope_value if controller.class.respond_to? :t_scope_value + # end end ActionMailer::Base.class_eval do - def t_scope_value - controller.class.t_scope_value if controller.class.respond_to? :t_scope_value - end + # def t_scope_value + # controller.class.t_scope_value if controller.class.respond_to? :t_scope_value + # end # def t_scope scope # raise 'stub! use the same' # @t_scope = scope # @body[:t_scope] = @t_scope # end \ No newline at end of file