-
Sean Doyle authored
When translating a `<button>` element's contents, it is tedious to make the translation text available to a block scope. For instance, when rendering a `<button type="submit">` with an SVG element as its child, passing translated label text to that SVG element's [`<title>`][svg-title] element requires an extra call to `I18n.translate`. Prior to this commit, doing so would require a double lookup of the translation key: ```erb <%# one time here, implicitly %> <%= form.button do %> <svg> <title> <!-- one time here, explicitly --> <%= translate("helpers.submit.post.create") %> </title> <!-- ... --> </svg> <% end %> ``` This commit modifies the `ActionView::Helpers::FormBuilder#button` to check for invocations that are passed a block, and conditionally yield the contents of `submit_default_value` as the argument. The new view code might look something like this: ```erb <%= form.button do |text| %> <svg> <title><%= text %></title> <!-- ... --> </svg> <% end %> ``` Callers of the helper are still free to omit the block parameter. [svg-title]: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/title
Sean Doyle authoredWhen translating a `<button>` element's contents, it is tedious to make the translation text available to a block scope. For instance, when rendering a `<button type="submit">` with an SVG element as its child, passing translated label text to that SVG element's [`<title>`][svg-title] element requires an extra call to `I18n.translate`. Prior to this commit, doing so would require a double lookup of the translation key: ```erb <%# one time here, implicitly %> <%= form.button do %> <svg> <title> <!-- one time here, explicitly --> <%= translate("helpers.submit.post.create") %> </title> <!-- ... --> </svg> <% end %> ``` This commit modifies the `ActionView::Helpers::FormBuilder#button` to check for invocations that are passed a block, and conditionally yield the contents of `submit_default_value` as the argument. The new view code might look something like this: ```erb <%= form.button do |text| %> <svg> <title><%= text %></title> <!-- ... --> </svg> <% end %> ``` Callers of the helper are still free to omit the block parameter. [svg-title]: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/title
Loading