Fix ambiguity in i18n lookup, closes #384.
This commit is contained in:
parent
031e3324ca
commit
259640e4cb
|
@ -120,7 +120,7 @@ module SimpleForm
|
||||||
# simple_form.{namespace}.{model}.{nested}.{attribute}
|
# simple_form.{namespace}.{model}.{nested}.{attribute}
|
||||||
# simple_form.{namespace}.{nested}.{action}.{attribute}
|
# simple_form.{namespace}.{nested}.{action}.{attribute}
|
||||||
# simple_form.{namespace}.{nested}.{attribute}
|
# simple_form.{namespace}.{nested}.{attribute}
|
||||||
# simple_form.{namespace}.{attribute}
|
# simple_form.{namespace}.defaults.{attribute}
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
#
|
#
|
||||||
|
@ -144,7 +144,7 @@ module SimpleForm
|
||||||
lookups << :"#{joined_model_names}.#{lookup_action}.#{reflection_or_attribute_name}"
|
lookups << :"#{joined_model_names}.#{lookup_action}.#{reflection_or_attribute_name}"
|
||||||
lookups << :"#{joined_model_names}.#{reflection_or_attribute_name}"
|
lookups << :"#{joined_model_names}.#{reflection_or_attribute_name}"
|
||||||
end
|
end
|
||||||
lookups << :"#{attribute_name}" unless reflection
|
lookups << :"defaults.#{attribute_name}" unless reflection
|
||||||
lookups << default
|
lookups << default
|
||||||
|
|
||||||
I18n.t(lookups.shift, :scope => :"simple_form.#{namespace}", :default => lookups).presence
|
I18n.t(lookups.shift, :scope => :"simple_form.#{namespace}", :default => lookups).presence
|
||||||
|
|
|
@ -73,7 +73,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'input should use i18n based only on attribute to lookup translation' do
|
test 'input should use i18n based only on attribute to lookup translation' do
|
||||||
store_translations(:en, :simple_form => { :labels => { :age => 'Idade' } } ) do
|
store_translations(:en, :simple_form => { :labels => { :defaults => {:age => 'Idade'} } } ) do
|
||||||
with_label_for @user, :age, :integer
|
with_label_for @user, :age, :integer
|
||||||
assert_select 'label[for=user_age]', /Idade/
|
assert_select 'label[for=user_age]', /Idade/
|
||||||
end
|
end
|
||||||
|
@ -81,7 +81,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
||||||
|
|
||||||
test 'input should not use i18n label if translate is false' do
|
test 'input should not use i18n label if translate is false' do
|
||||||
swap SimpleForm, :translate_labels => false do
|
swap SimpleForm, :translate_labels => false do
|
||||||
store_translations(:en, :simple_form => { :labels => { :age => 'Idade' } } ) do
|
store_translations(:en, :simple_form => { :labels => { :defaults => {:age => 'Idade'} } } ) do
|
||||||
with_label_for @user, :age, :integer
|
with_label_for @user, :age, :integer
|
||||||
assert_select 'label[for=user_age]', /Age/
|
assert_select 'label[for=user_age]', /Age/
|
||||||
end
|
end
|
||||||
|
|
|
@ -90,7 +90,7 @@ class HintTest < ActionView::TestCase
|
||||||
|
|
||||||
test 'hint should use i18n just with attribute to lookup translation' do
|
test 'hint should use i18n just with attribute to lookup translation' do
|
||||||
store_translations(:en, :simple_form => { :hints => {
|
store_translations(:en, :simple_form => { :hints => {
|
||||||
:name => 'Content of this input will be downcased...'
|
:defaults => {:name => 'Content of this input will be downcased...'}
|
||||||
} }) do
|
} }) do
|
||||||
with_hint_for @user, :name
|
with_hint_for @user, :name
|
||||||
assert_select 'span.hint', 'Content of this input will be downcased...'
|
assert_select 'span.hint', 'Content of this input will be downcased...'
|
||||||
|
|
Loading…
Reference in New Issue