aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-04-28 00:36:32 -0700
committerJosé Valim <jose.valim@gmail.com>2011-04-28 00:36:32 -0700
commitbe55228bbf7df58d5eff483ae1b105fa7680de71 (patch)
tree9dff6730971f28b682062bf7a7b9447480f8e4ff
parent2a25c5818b03d7d6cd63aad180bff23479dbd861 (diff)
parenta07cee62c7d23ec587ef961beb35ce3ac63df340 (diff)
downloadrails-be55228bbf7df58d5eff483ae1b105fa7680de71.tar.gz
rails-be55228bbf7df58d5eff483ae1b105fa7680de71.tar.bz2
rails-be55228bbf7df58d5eff483ae1b105fa7680de71.zip
Merged pull request #333 from jgarber/master.
Specific translations for labels with values
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb3
-rw-r--r--actionpack/test/template/form_helper_test.rb12
2 files changed, 13 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 440acafa88..efe30441b1 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -947,7 +947,8 @@ module ActionView
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
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 7afab3179c..c25c850eb3 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -24,7 +24,10 @@ class FormHelperTest < ActionView::TestCase
:helpers => {
:label => {
:post => {
- :body => "Write entire text here"
+ :body => "Write entire text here",
+ :color => {
+ :red => "Rojo"
+ }
}
}
}
@@ -141,6 +144,13 @@ class FormHelperTest < ActionView::TestCase
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