Skip to content

Commit a6b3902

Browse files
committed
added the possibility to translate the placeholder and title attributes in the PHP form templates (refs #4194)
1 parent 5ca64b4 commit a6b3902

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
{% if required %}
226226
{% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
227227
{% endif %}
228-
<label{% for attrname,attrvalue in label_attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>{{ label|trans({}, translation_domain) }}</label>
228+
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ label|trans({}, translation_domain) }}</label>
229229
{% endspaceless %}
230230
{% endblock form_label %}
231231

@@ -305,14 +305,14 @@
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 %}{% if attrname in ['placeholder', 'title'] %}{{attrname}}="{{attrvalue|trans({}, translation_domain)}}" {% else %}{{attrname}}="{{attrvalue}}" {% endif %}{% 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

312312
{% block widget_container_attributes %}
313313
{% spaceless %}
314314
{% if id is not empty %}id="{{ id }}" {% endif %}
315-
{% for attrname,attrvalue in attr %}{{attrname}}="{{attrvalue}}" {% endfor %}
315+
{% for attrname, attrvalue in attr %}{{ attrname }}="{{ attrvalue }}" {% endfor %}
316316
{% endspaceless %}
317317
{% endblock widget_container_attributes %}
318318

src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget_attributes.html.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
<?php if ($required): ?>required="required" <?php endif ?>
66
<?php if ($max_length): ?>maxlength="<?php echo $view->escape($max_length) ?>" <?php endif ?>
77
<?php if ($pattern): ?>pattern="<?php echo $view->escape($pattern) ?>" <?php endif ?>
8-
<?php foreach ($attr as $k => $v) { printf('%s="%s" ', $view->escape($k), $view->escape($v)); } ?>
9-
8+
<?php foreach ($attr as $k => $v): ?>
9+
<?php printf('%s="%s" ', $view->escape($k), $view->escape(in_array($v, array('placeholder', 'title')) ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?>
10+
<?php endforeach; ?>

0 commit comments

Comments
 (0)