Only translate prompts and include_blank if value is :translate
This commit is contained in:
parent
0b4d83082a
commit
5ce1d04362
|
@ -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
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue