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
|
end
|
||||||
|
|
||||||
def translate_option(options, key)
|
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]
|
options[key] = translate(namespace, true)
|
||||||
when :translate, :t
|
|
||||||
translate(namespace, true)
|
|
||||||
else
|
|
||||||
I18n.t(options[key], scope: :"simple_form.#{namespace}")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -111,21 +111,11 @@ class CollectionSelectInputTest < ActionView::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'input should translate include blank when set to :t' do
|
test 'input should translate include blank with a default' do
|
||||||
store_translations(:en, simple_form: { include_blanks: { user: {
|
store_translations(:en, simple_form: { include_blanks: { defaults: {
|
||||||
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: {
|
|
||||||
age: 'Rather not say',
|
age: 'Rather not say',
|
||||||
user: { age: 'Should be overridden' }
|
} } }) do
|
||||||
} } ) do
|
with_input_for @user, :age, :select, collection: 18..30, include_blank: :translate
|
||||||
with_input_for @user, :age, :select, collection: 18..30, include_blank: :age
|
|
||||||
assert_select 'select option[value=]', 'Rather not say'
|
assert_select 'select option[value=]', 'Rather not say'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -190,21 +180,11 @@ class CollectionSelectInputTest < ActionView::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'input should translate prompt when set to :t' do
|
test 'input should translate prompt with a default' do
|
||||||
store_translations(:en, simple_form: { prompts: { user: {
|
store_translations(:en, simple_form: { prompts: { defaults: {
|
||||||
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: {
|
|
||||||
age: 'Select age:',
|
age: 'Select age:',
|
||||||
user: { age: 'Should be overridden' }
|
} } }) do
|
||||||
} } ) do
|
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
|
||||||
with_input_for @user, :age, :select, collection: 18..30, prompt: :age
|
|
||||||
assert_select 'select option[value=]', 'Select age:'
|
assert_select 'select option[value=]', 'Select age:'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue