Skip to content

Commit 5ca64b4

Browse files
committed
merged branch andrefgneves/translate-widget-attributes (PR #4194)
Commits ------- 23bad29 Added translation to placeholder and title attributes Discussion ---------- Added translation to placeholder and title attributes --------------------------------------------------------------------------- by schmittjoh at 2012-05-03T13:52:38Z Better translate it where it is defined. Dynamic translations are usually not desirable as they cannot be automatically extracted, and thus require more work. --------------------------------------------------------------------------- by ruimarinho at 2012-05-03T13:57:30Z @schmittjoh but isn't that the same case as with labels for instance? I don't think injecting the translator service into the form type would require less work than what this PR suggests. --------------------------------------------------------------------------- by schmittjoh at 2012-05-03T14:02:02Z Yeah, same thing. There might be some cases where it's fine, but in general, we should try to not translate dynamic vars. --------------------------------------------------------------------------- by ruimarinho at 2012-05-03T14:17:44Z @schmittjoh I think that's one of those cases, since these attributes in particular (title and placeholder) are intended to aid the user with a brief description. I understand (and agree) with your concern regarding dynamic vars, but in my opinion this is a use case where it is worth it. Just my two cents :) --------------------------------------------------------------------------- by stof at 2012-05-03T18:07:01Z @schmittjoh the issue is that translating the label before the template would require injecting the translator in the form types (as the form label can be set there) and would force the user to duplicate the translation process if they pass the label explicitly in the template.
2 parents fc34ed1 + 23bad29 commit 5ca64b4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@
305305
{% block widget_attributes %}
306306
{% spaceless %}
307307
id="{{ id }}" name="{{ full_name }}"{% if read_only %} readonly="readonly"{% endif %}{% if disabled %} disabled="disabled"{% endif %}{% if required %} required="required"{% endif %}{% if max_length %} maxlength="{{ max_length }}"{% endif %}{% if pattern %} pattern="{{ pattern }}"{% endif %}
308-
{% for attrname,attrvalue in attr %}{{attrname}}="{{attrvalue}}" {% endfor %}
308+
{% for attrname,attrvalue in attr %}{% if attrname in ['placeholder', 'title'] %}{{attrname}}="{{attrvalue|trans({}, translation_domain)}}" {% else %}{{attrname}}="{{attrvalue}}" {% endif %}{% endfor %}
309309
{% endspaceless %}
310310
{% endblock widget_attributes %}
311311

0 commit comments

Comments
 (0)