1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Change translation key of submit_tag from module_name_class_name to module_name/class_name

Currently submit_tag value translation does not support i18n key style
locale key.
It confuses me a bit because many other components support i18n key
style locale key.
I added i18n key style locale key support to submit tag.
This commit is contained in:
Rui Onodera 2016-10-16 21:21:03 +09:00
parent f7157e48ea
commit e579c7430a
4 changed files with 48 additions and 3 deletions

View file

@ -1,5 +1,9 @@
## Rails 6.0.0.alpha (Unreleased) ##
* Change translation key of `submit_tag` from `module_name_class_name` to `module_name/class_name`.
*Rui Onodera*
* Rails 6 requires Ruby 2.4.1 or newer.
*Jeremy Daer*

View file

@ -2266,7 +2266,12 @@ module ActionView
end
defaults = []
defaults << :"helpers.submit.#{object_name}.#{key}"
# Object is a model and it is not overwritten by as and scope option.
if object.respond_to?(:model_name) && object_name.to_s == model.downcase
defaults << :"helpers.submit.#{object.model_name.i18n_key}.#{key}"
else
defaults << :"helpers.submit.#{object_name}.#{key}"
end
defaults << :"helpers.submit.#{key}"
defaults << "#{key.to_s.humanize} #{model}"

View file

@ -190,6 +190,9 @@ class FormWithActsLikeFormForTest < FormWithTest
submit: "Save changes",
another_post: {
update: "Update your %{model}"
},
"blog/post": {
update: "Update your %{model}"
}
}
}
@ -962,7 +965,7 @@ class FormWithActsLikeFormForTest < FormWithTest
end
end
def test_submit_with_object_and_nested_lookup
def test_submit_with_object_which_is_overwritten_by_scope_option
with_locale :submit do
form_with(model: @post, scope: :another_post) do |f|
concat f.submit
@ -976,6 +979,21 @@ class FormWithActsLikeFormForTest < FormWithTest
end
end
def test_submit_with_object_which_is_namespaced
blog_post = Blog::Post.new("And his name will be forty and four.", 44)
with_locale :submit do
form_with(model: blog_post) do |f|
concat f.submit
end
expected = whole_form("/posts/44", method: "patch") do
"<input name='commit' data-disable-with='Update your Post' type='submit' value='Update your Post' />"
end
assert_dom_equal expected, output_buffer
end
end
def test_fields_with_attributes_not_on_model
form_with(model: @post) do |f|
concat f.fields(:comment) { |c|

View file

@ -68,6 +68,9 @@ class FormHelperTest < ActionView::TestCase
submit: "Save changes",
another_post: {
update: "Update your %{model}"
},
"blog/post": {
update: "Update your %{model}"
}
}
}
@ -2271,7 +2274,7 @@ class FormHelperTest < ActionView::TestCase
end
end
def test_submit_with_object_and_nested_lookup
def test_submit_with_object_which_is_overwritten_by_as_option
with_locale :submit do
form_for(@post, as: :another_post) do |f|
concat f.submit
@ -2285,6 +2288,21 @@ class FormHelperTest < ActionView::TestCase
end
end
def test_submit_with_object_which_is_namespaced
blog_post = Blog::Post.new("And his name will be forty and four.", 44)
with_locale :submit do
form_for(blog_post) do |f|
concat f.submit
end
expected = whole_form("/posts/44", "edit_post_44", "edit_post", method: "patch") do
"<input name='commit' data-disable-with='Update your Post' type='submit' value='Update your Post' />"
end
assert_dom_equal expected, output_buffer
end
end
def test_nested_fields_for
@comment.body = "Hello World"
form_for(@post) do |f|