diff --git a/lib/simple_form/inputs/collection_input.rb b/lib/simple_form/inputs/collection_input.rb index 975bee1a..1ac15de1 100644 --- a/lib/simple_form/inputs/collection_input.rb +++ b/lib/simple_form/inputs/collection_input.rb @@ -105,11 +105,13 @@ module SimpleForm def translate_option(options, key) return unless options[key].is_a? Symbol + namespace = key.to_s.pluralize + options[key] = case options[key] when :translate, :t - translate(key, true) + translate(namespace, true) else - I18n.t(options[key], scope: :"simple_form.#{key}") + I18n.t(options[key], scope: :"simple_form.#{namespace}") end end end diff --git a/test/inputs/collection_select_input_test.rb b/test/inputs/collection_select_input_test.rb index 252b2fd0..3c736a64 100644 --- a/test/inputs/collection_select_input_test.rb +++ b/test/inputs/collection_select_input_test.rb @@ -97,7 +97,7 @@ class CollectionSelectInputTest < ActionView::TestCase end test 'input should translate include blank when set to :translate' do - store_translations(:en, :simple_form => { :include_blank => { :user => { + store_translations(:en, :simple_form => { :include_blanks => { :user => { :age => 'Rather not say' } } } ) do with_input_for @user, :age, :select, :collection => 18..30, :include_blank => :translate @@ -106,7 +106,7 @@ class CollectionSelectInputTest < ActionView::TestCase end test 'input should translate include blank when set to :t' do - store_translations(:en, :simple_form => { :include_blank => { :user => { + store_translations(:en, :simple_form => { :include_blanks => { :user => { :age => 'Rather not say' } } } ) do with_input_for @user, :age, :select, :collection => 18..30, :include_blank => :t @@ -115,7 +115,7 @@ class CollectionSelectInputTest < ActionView::TestCase end test 'input should translate include blank with a particular key' do - store_translations(:en, :simple_form => { :include_blank => { + store_translations(:en, :simple_form => { :include_blanks => { :age => 'Rather not say', :user => { :age => 'Should be overridden' } } } ) do @@ -125,7 +125,7 @@ class CollectionSelectInputTest < ActionView::TestCase end test 'input should not translate include blank when set to a string' do - store_translations(:en, :simple_form => { :include_blank => { :user => { + store_translations(:en, :simple_form => { :include_blanks => { :user => { :age => 'Rather not say' } } } ) do with_input_for @user, :age, :select, :collection => 18..30, :include_blank => 'Young at heart' @@ -134,7 +134,7 @@ class CollectionSelectInputTest < ActionView::TestCase end test 'input should not translate include blank when automatically set' do - store_translations(:en, :simple_form => { :include_blank => { :user => { + store_translations(:en, :simple_form => { :include_blanks => { :user => { :age => 'Rather not say' } } } ) do with_input_for @user, :age, :select, :collection => 18..30 @@ -143,7 +143,7 @@ class CollectionSelectInputTest < ActionView::TestCase end test 'input should not translate include blank when set to true' do - store_translations(:en, :simple_form => { :include_blank => { :user => { + store_translations(:en, :simple_form => { :include_blanks => { :user => { :age => 'Rather not say' } } } ) do with_input_for @user, :age, :select, :collection => 18..30, :include_blank => true @@ -152,7 +152,7 @@ class CollectionSelectInputTest < ActionView::TestCase end test 'input should not translate include blank when set to false' do - store_translations(:en, :simple_form => { :include_blank => { :user => { + store_translations(:en, :simple_form => { :include_blanks => { :user => { :age => 'Rather not say' } } } ) do with_input_for @user, :age, :select, :collection => 18..30, :include_blank => false @@ -176,7 +176,7 @@ class CollectionSelectInputTest < ActionView::TestCase end test 'input should translate prompt when set to :translate' do - store_translations(:en, :simple_form => { :prompt => { :user => { + store_translations(:en, :simple_form => { :prompts => { :user => { :age => 'Select age:' } } } ) do with_input_for @user, :age, :select, :collection => 18..30, :prompt => :translate @@ -185,7 +185,7 @@ class CollectionSelectInputTest < ActionView::TestCase end test 'input should translate prompt when set to :t' do - store_translations(:en, :simple_form => { :prompt => { :user => { + store_translations(:en, :simple_form => { :prompts => { :user => { :age => 'Select age:' } } } ) do with_input_for @user, :age, :select, :collection => 18..30, :prompt => :t @@ -194,7 +194,7 @@ class CollectionSelectInputTest < ActionView::TestCase end test 'input should translate prompt with a particular key' do - store_translations(:en, :simple_form => { :prompt => { + store_translations(:en, :simple_form => { :prompts => { :age => 'Select age:', :user => { :age => 'Should be overridden' } } } ) do @@ -204,7 +204,7 @@ class CollectionSelectInputTest < ActionView::TestCase end test 'input should not translate prompt when set to a string' do - store_translations(:en, :simple_form => { :prompt => { :user => { + store_translations(:en, :simple_form => { :prompts => { :user => { :age => 'Select age:' } } } ) do with_input_for @user, :age, :select, :collection => 18..30, :prompt => 'Do it:' @@ -213,7 +213,7 @@ class CollectionSelectInputTest < ActionView::TestCase end test 'input should not translate prompt when set to false' do - store_translations(:en, :simple_form => { :prompt => { :user => { + store_translations(:en, :simple_form => { :prompts => { :user => { :age => 'Select age:' } } } ) do with_input_for @user, :age, :select, :collection => 18..30, :prompt => false