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

Merge pull request #26799 from deraru/support-i18n-key-in-submit-tag

Support i18n key at translation of value in submit tag
This commit is contained in:
Rafael França 2018-02-26 22:30:32 -05:00 committed by GitHub
commit f86b221a53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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|