commit da196130cc8995baffd2523e707b628d0add462f Author: Niels Ganser Date: Wed Jan 21 16:55:58 2009 +0100 ActionView::Helpers::InstanceTag.to_label_tag now returns ActiveRecord::Base.human_attribute_name(:attribute).titleize by default. This closes #745 "Form label should use I18n" (http://rails.lighthouseapp.com/projects/8994/tickets/745-form-label-should-use-i18n) diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 621e294..eb9796d 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -545,7 +545,11 @@ module ActionView add_default_name_and_id(name_and_id) options.delete("index") options["for"] ||= name_and_id["id"] - content = (text.blank? ? nil : text.to_s) || method_name.humanize + if text.blank? + content = object.class.respond_to?(:human_attribute_name) ? object.class.human_attribute_name(method_name).titleize : method_name.humanize + else + content = text.to_s + end label_tag(name_and_id["id"], content, options) end diff --git a/actionpack/test/template/form_helper_i18n_test.rb b/actionpack/test/template/form_helper_i18n_test.rb new file mode 100644 index 0000000..0d8bb2e --- /dev/null +++ b/actionpack/test/template/form_helper_i18n_test.rb @@ -0,0 +1,20 @@ +require 'abstract_unit' +require 'active_record_unit' + +class FormHelperI18nTest < ActionView::TestCase + tests ActionView::Helpers::FormHelper + + uses_mocha 'form_helper_i18n_test' do + + def test_form_for_with_translated_labels + Reply.stubs(:human_attribute_name).with('title').returns("translated title") + fields_for(Reply.new) do |f| + @string = f.label(:title) + end + assert_equal "", @string + end + + end + +end +