mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
I18n: use I18n for select helpers' prompt text
[#2252 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
committed by
Jeremy Kemper
parent
a7ca5595a2
commit
cc9af20da7
@@ -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
|
||||
|
||||
@@ -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"
|
||||
27
actionpack/test/template/form_options_helper_i18n_test.rb
Normal file
27
actionpack/test/template/form_options_helper_i18n_test.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
require 'abstract_unit'
|
||||
|
||||
class FormOptionsHelperI18nTests < ActionView::TestCase
|
||||
tests ActionView::Helpers::FormOptionsHelper
|
||||
|
||||
def setup
|
||||
@prompt_message = 'Select!'
|
||||
I18n.backend.send(:init_translations)
|
||||
I18n.backend.store_translations :en, :support => { :select => { :prompt => @prompt_message } }
|
||||
end
|
||||
|
||||
def teardown
|
||||
I18n.backend = I18n::Backend::Simple.new
|
||||
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
|
||||
Reference in New Issue
Block a user