From 5ce1d04362c92d4e86cb99d1ba31aea739c0b6d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 3 Apr 2014 15:22:09 -0300 Subject: [PATCH] Only translate prompts and include_blank if value is :translate --- lib/simple_form/inputs/collection_input.rb | 12 ++----- test/inputs/collection_select_input_test.rb | 40 ++++++--------------- 2 files changed, 13 insertions(+), 39 deletions(-) diff --git a/lib/simple_form/inputs/collection_input.rb b/lib/simple_form/inputs/collection_input.rb index 57958997..e3ec5058 100644 --- a/lib/simple_form/inputs/collection_input.rb +++ b/lib/simple_form/inputs/collection_input.rb @@ -107,18 +107,12 @@ module SimpleForm end def translate_option(options, key) - return unless options[key].is_a? Symbol + if options[key] == :translate + namespace = key.to_s.pluralize - namespace = key.to_s.pluralize - - options[key] = case options[key] - when :translate, :t - translate(namespace, true) - else - I18n.t(options[key], scope: :"simple_form.#{namespace}") + options[key] = translate(namespace, true) end end end end end - diff --git a/test/inputs/collection_select_input_test.rb b/test/inputs/collection_select_input_test.rb index b8e41dd5..343046ec 100644 --- a/test/inputs/collection_select_input_test.rb +++ b/test/inputs/collection_select_input_test.rb @@ -105,27 +105,17 @@ class CollectionSelectInputTest < ActionView::TestCase test 'input should translate include blank when set to :translate' do store_translations(:en, simple_form: { include_blanks: { user: { age: 'Rather not say' - } } } ) do + } } }) do with_input_for @user, :age, :select, collection: 18..30, include_blank: :translate assert_select 'select option[value=]', 'Rather not say' end end - test 'input should translate include blank when set to :t' do - 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 - assert_select 'select option[value=]', 'Rather not say' - end - end - - test 'input should translate include blank with a particular key' do - store_translations(:en, simple_form: { include_blanks: { + test 'input should translate include blank with a default' do + store_translations(:en, simple_form: { include_blanks: { defaults: { age: 'Rather not say', - user: { age: 'Should be overridden' } - } } ) do - with_input_for @user, :age, :select, collection: 18..30, include_blank: :age + } } }) do + with_input_for @user, :age, :select, collection: 18..30, include_blank: :translate assert_select 'select option[value=]', 'Rather not say' end end @@ -184,27 +174,17 @@ class CollectionSelectInputTest < ActionView::TestCase test 'input should translate prompt when set to :translate' do store_translations(:en, simple_form: { prompts: { user: { age: 'Select age:' - } } } ) do + } } }) do with_input_for @user, :age, :select, collection: 18..30, prompt: :translate assert_select 'select option[value=]', 'Select age:' end end - test 'input should translate prompt when set to :t' do - store_translations(:en, simple_form: { prompts: { user: { - age: 'Select age:' - } } } ) do - with_input_for @user, :age, :select, collection: 18..30, prompt: :t - assert_select 'select option[value=]', 'Select age:' - end - end - - test 'input should translate prompt with a particular key' do - store_translations(:en, simple_form: { prompts: { + test 'input should translate prompt with a default' do + store_translations(:en, simple_form: { prompts: { defaults: { age: 'Select age:', - user: { age: 'Should be overridden' } - } } ) do - with_input_for @user, :age, :select, collection: 18..30, prompt: :age + } } }) do + with_input_for @user, :age, :select, collection: 18..30, prompt: :translate assert_select 'select option[value=]', 'Select age:' end end