Created
May 14, 2011 02:36
-
-
Save AquaGeek/971856 to your computer and use it in GitHub Desktop.
Rails Lighthouse ticket #6753
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 3b8aa2b5cbfd5c72f2143f12236e6fad734b61e5 Mon Sep 17 00:00:00 2001 | |
| From: Jason Garber <jg@jasongarber.com> | |
| Date: Wed, 27 Apr 2011 15:06:19 -0600 | |
| Subject: [PATCH] Allow a label with the value option to have value-specific translations. | |
| --- | |
| actionpack/lib/action_view/helpers/form_helper.rb | 3 ++- | |
| actionpack/test/template/form_helper_test.rb | 12 +++++++++++- | |
| 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 440acaf..efe3044 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 7afab31..c25c850 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 | |
| -- | |
| 1.7.2.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment