Skip to content
This repository
Browse code

I18n: use I18n for select helpers' prompt text

[#2252 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit cc9af20da7af98464ece18d4abc6a22ef3f00b5d 1 parent a7ca559
Akira Matsuda authored August 26, 2009 jeremy committed August 26, 2009
3  actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -571,7 +571,8 @@ def add_options(option_tags, options, value = nil)
571 571
             option_tags = "<option value=\"\">#{options[:include_blank] if options[:include_blank].kind_of?(String)}</option>\n" + option_tags
572 572
           end
573 573
           if value.blank? && options[:prompt]
574  
-            ("<option value=\"\">#{options[:prompt].kind_of?(String) ? options[:prompt] : 'Please select'}</option>\n") + option_tags
  574
+            prompt = options[:prompt].kind_of?(String) ? options[:prompt] : I18n.translate('support.select.prompt', :default => 'Please select')
  575
+            "<option value=\"\">#{prompt}</option>\n" + option_tags
575 576
           else
576 577
             option_tags
577 578
           end
4  actionpack/lib/action_view/locale/en.yml
@@ -108,3 +108,7 @@
108 108
         # The variable :count is also available
109 109
         body: "There were problems with the following fields:"
110 110
 
  111
+  support:
  112
+    select:
  113
+      # default value for :prompt => true in FormOptionsHelper
  114
+      prompt: "Please select"
27  actionpack/test/template/form_options_helper_i18n_test.rb
... ...
@@ -0,0 +1,27 @@
  1
+require 'abstract_unit'
  2
+
  3
+class FormOptionsHelperI18nTests < ActionView::TestCase
  4
+  tests ActionView::Helpers::FormOptionsHelper
  5
+
  6
+  def setup
  7
+    @prompt_message = 'Select!'
  8
+    I18n.backend.send(:init_translations)
  9
+    I18n.backend.store_translations :en, :support => { :select => { :prompt => @prompt_message } }
  10
+  end
  11
+
  12
+  def teardown
  13
+    I18n.backend = I18n::Backend::Simple.new
  14
+  end
  15
+
  16
+  def test_select_with_prompt_true_translates_prompt_message
  17
+    I18n.expects(:translate).with('support.select.prompt', { :default => 'Please select' })
  18
+    select('post', 'category', [], :prompt => true)
  19
+  end
  20
+
  21
+  def test_select_with_translated_prompt
  22
+    assert_dom_equal(
  23
+      %Q(<select id="post_category" name="post[category]"><option value="">#{@prompt_message}</option>\n</select>),
  24
+      select('post', 'category', [], :prompt => true)
  25
+    )
  26
+  end
  27
+end

0 notes on commit cc9af20

Please sign in to comment.
Something went wrong with that request. Please try again.