i18n label in rails (monkey patch)

I18n label is still not supported in rails 2.3.2. Here is the patch to make it work. However, I don’t want to change the source code of rails. Hence, I create a monkey patch.

module ActionView
  module Helpers
    class InstanceTag
      def to_label_tag_with_i18n(text = nil, options = {})
        text ||= object.class.human_attribute_name(method_name) if object.class.respond_to?(:human_attribute_name)

        to_label_tag_without_i18n(text, options)
      end

      alias_method_chain :to_label_tag, :i18n
    end
  end
end

Load the file in the environment.rb or any file in confit/initializers will make it work.


blogroll

social