diff --git a/lib/simple_form/inputs/collection_input.rb b/lib/simple_form/inputs/collection_input.rb index e40b211b..91c3d73e 100644 --- a/lib/simple_form/inputs/collection_input.rb +++ b/lib/simple_form/inputs/collection_input.rb @@ -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 diff --git a/test/inputs/collection_select_input_test.rb b/test/inputs/collection_select_input_test.rb index f10c595c..9b3395d0 100644 --- a/test/inputs/collection_select_input_test.rb +++ b/test/inputs/collection_select_input_test.rb @@ -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:'