提交 e579c743 编写于 作者: R Rui Onodera

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.
上级 f7157e48
## 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*
......
......@@ -2266,7 +2266,12 @@ def submit_default_value
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}"
......
......@@ -190,6 +190,9 @@ def form_with(*)
submit: "Save changes",
another_post: {
update: "Update your %{model}"
},
"blog/post": {
update: "Update your %{model}"
}
}
}
......@@ -962,7 +965,7 @@ def test_submit_without_object_and_locale_strings
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 @@ def test_submit_with_object_and_nested_lookup
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|
......
......@@ -68,6 +68,9 @@ def form_for(*)
submit: "Save changes",
another_post: {
update: "Update your %{model}"
},
"blog/post": {
update: "Update your %{model}"
}
}
}
......@@ -2271,7 +2274,7 @@ def test_submit_without_object_and_locale_strings
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 @@ def test_submit_with_object_and_nested_lookup
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|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册