Allow i18n key for include_blank and prompt
This commit is contained in:
parent
f4c883e8fb
commit
d502ecf14b
|
@ -23,7 +23,7 @@ module SimpleForm
|
|||
options[:include_blank] = true unless skip_include_blank?
|
||||
|
||||
[:prompt, :include_blank].each do |key|
|
||||
options[key] = translate(key, true) if options[key] == :translate
|
||||
translate_option options, key
|
||||
end
|
||||
|
||||
options
|
||||
|
@ -101,6 +101,16 @@ module SimpleForm
|
|||
true
|
||||
end
|
||||
end
|
||||
|
||||
def translate_option(options, key)
|
||||
return unless options[key].is_a? Symbol
|
||||
|
||||
options[key] = if options[key] == :translate
|
||||
translate(key, true)
|
||||
else
|
||||
I18n.t(options[key], scope: :"simple_form.#{key}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -105,6 +105,16 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'input should translate include blank with a particular key' do
|
||||
store_translations(:en, :simple_form => { :include_blank => {
|
||||
:age => 'Rather not say',
|
||||
:user => { :age => 'Should be overridden' }
|
||||
} } ) do
|
||||
with_input_for @user, :age, :select, :collection => 18..30, :include_blank => :age
|
||||
assert_select 'select option[value=]', 'Rather not say'
|
||||
end
|
||||
end
|
||||
|
||||
test 'input should not translate include blank when set to a string' do
|
||||
store_translations(:en, :simple_form => { :include_blank => { :user => {
|
||||
:age => 'Rather not say'
|
||||
|
@ -165,6 +175,16 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'input should translate prompt with a particular key' do
|
||||
store_translations(:en, :simple_form => { :prompt => {
|
||||
:age => 'Select age:',
|
||||
:user => { :age => 'Should be overridden' }
|
||||
} } ) do
|
||||
with_input_for @user, :age, :select, :collection => 18..30, :prompt => :age
|
||||
assert_select 'select option[value=]', 'Select age:'
|
||||
end
|
||||
end
|
||||
|
||||
test 'input should not translate prompt when set to a string' do
|
||||
store_translations(:en, :simple_form => { :prompt => { :user => {
|
||||
:age => 'Select age:'
|
||||
|
|
Loading…
Reference in New Issue