aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAkira Matsuda <ronnie@dio.jp>2009-08-26 14:00:06 +0200
committerJeremy Kemper <jeremy@bitsweat.net>2009-08-26 11:29:16 -0700
commitadedf72821a5623227ce91e6b298838e692477e4 (patch)
treef2de096228c4c74b915311d0314f64bdb8b749ff /actionpack
parent9408fcd2e858ae48dd30d9e8d1bb1dcbbfffb840 (diff)
downloadrails-adedf72821a5623227ce91e6b298838e692477e4.tar.gz
rails-adedf72821a5623227ce91e6b298838e692477e4.tar.bz2
rails-adedf72821a5623227ce91e6b298838e692477e4.zip
I18n: use I18n for select helpers' prompt text
[#2252 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/helpers/form_options_helper.rb3
-rw-r--r--actionpack/lib/action_view/locale/en.yml4
-rw-r--r--actionpack/test/template/form_options_helper_i18n_test.rb22
3 files changed, 28 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb
index 4620a52272..3db5202e7d 100644
--- a/actionpack/lib/action_view/helpers/form_options_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -571,7 +571,8 @@ module ActionView
option_tags = "<option value=\"\">#{options[:include_blank] if options[:include_blank].kind_of?(String)}</option>\n" + option_tags
end
if value.blank? && options[:prompt]
- ("<option value=\"\">#{options[:prompt].kind_of?(String) ? options[:prompt] : 'Please select'}</option>\n") + option_tags
+ prompt = options[:prompt].kind_of?(String) ? options[:prompt] : I18n.translate('support.select.prompt', :default => 'Please select')
+ "<option value=\"\">#{prompt}</option>\n" + option_tags
else
option_tags
end
diff --git a/actionpack/lib/action_view/locale/en.yml b/actionpack/lib/action_view/locale/en.yml
index afe35691bc..c82cd07ec2 100644
--- a/actionpack/lib/action_view/locale/en.yml
+++ b/actionpack/lib/action_view/locale/en.yml
@@ -108,3 +108,7 @@
# The variable :count is also available
body: "There were problems with the following fields:"
+ support:
+ select:
+ # default value for :prompt => true in FormOptionsHelper
+ prompt: "Please select" \ No newline at end of file
diff --git a/actionpack/test/template/form_options_helper_i18n_test.rb b/actionpack/test/template/form_options_helper_i18n_test.rb
new file mode 100644
index 0000000000..4f25d41fc9
--- /dev/null
+++ b/actionpack/test/template/form_options_helper_i18n_test.rb
@@ -0,0 +1,22 @@
+require 'abstract_unit'
+
+class FormOptionsHelperI18nTests < ActionView::TestCase
+ tests ActionView::Helpers::FormOptionsHelper
+
+ def setup
+ @prompt_message = 'Select!'
+ I18n.backend.store_translations :en, :support => { :select => { :prompt => @prompt_message} }
+ end
+
+ def test_select_with_prompt_true_translates_prompt_message
+ I18n.expects(:translate).with('support.select.prompt', { :default => 'Please select' })
+ select 'post', 'category', [], :prompt => true
+ end
+
+ def test_select_with_translated_prompt
+ assert_dom_equal(
+ %Q(<select id="post_category" name="post[category]"><option value="">#{@prompt_message}</option>\n</select>),
+ select('post', 'category', [], :prompt => true)
+ )
+ end
+end \ No newline at end of file