Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merged pull request #333 from jgarber/master.

Specific translations for labels with values
  • Loading branch information...
commit be55228bbf7df58d5eff483ae1b105fa7680de71 2 parents 2a25c58 + a07cee6
@josevalim josevalim authored
View
3  actionpack/lib/action_view/helpers/form_helper.rb
@@ -947,7 +947,8 @@ def to_label_tag(text = nil, options = {}, &block)
label_tag(name_and_id["id"], options, &block)
else
content = if text.blank?
- I18n.t("helpers.label.#{object_name}.#{method_name}", :default => "").presence
+ method_and_value = tag_value.present? ? "#{method_name}.#{tag_value}" : method_name
+ I18n.t("helpers.label.#{object_name}.#{method_and_value}", :default => "").presence
else
text.to_s
end
View
12 actionpack/test/template/form_helper_test.rb
@@ -24,7 +24,10 @@ def setup
:helpers => {
:label => {
:post => {
- :body => "Write entire text here"
+ :body => "Write entire text here",
+ :color => {
+ :red => "Rojo"
+ }
}
}
}
@@ -141,6 +144,13 @@ def test_label_with_locales_and_options
I18n.locale = old_locale
end
+ def test_label_with_locales_and_value
+ old_locale, I18n.locale = I18n.locale, :label
+ assert_dom_equal('<label for="post_color_red">Rojo</label>', label(:post, :color, :value => "red"))
+ ensure
+ I18n.locale = old_locale
+ end
+
def test_label_with_for_attribute_as_symbol
assert_dom_equal('<label for="my_for">Title</label>', label(:post, :title, nil, :for => "my_for"))
end
Please sign in to comment.
Something went wrong with that request. Please try again.