From d5f2c5c20e2f8f104a1e67ba81166874cc472b9e Mon Sep 17 00:00:00 2001 From: Joshua Cody Date: Mon, 5 May 2014 17:48:53 -0500 Subject: Include label value in i18n attribute lookup Previously, only the object and method name from the label tag were used when looking up the translation for a label. If a value is given for the label, this ought to be additionally used. The following: # form.html.erb <%= form_for @post do |f| %> <%= f.label :type, value: "long" %> <% end %> # en.yml en: activerecord: attributes: post/long: "Long-form Post" Used to simply return "long", but now it will return "Long-form Post". --- actionview/lib/action_view/helpers/tags/label.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionview/lib/action_view/helpers/tags/label.rb') diff --git a/actionview/lib/action_view/helpers/tags/label.rb b/actionview/lib/action_view/helpers/tags/label.rb index 6335e3dd4d..a5bcaf8153 100644 --- a/actionview/lib/action_view/helpers/tags/label.rb +++ b/actionview/lib/action_view/helpers/tags/label.rb @@ -35,9 +35,9 @@ module ActionView if block_given? content = @template_object.capture(&block) else + method_and_value = tag_value.present? ? "#{@method_name}.#{tag_value}" : @method_name content = if @content.blank? @object_name.gsub!(/\[(.*)_attributes\]\[\d+\]/, '.\1') - method_and_value = tag_value.present? ? "#{@method_name}.#{tag_value}" : @method_name if object.respond_to?(:to_model) key = object.class.model_name.i18n_key @@ -51,7 +51,7 @@ module ActionView end content ||= if object && object.class.respond_to?(:human_attribute_name) - object.class.human_attribute_name(@method_name) + object.class.human_attribute_name(method_and_value) end content ||= @method_name.humanize -- cgit v1.2.3