From a6b39021282bed3d85d43337d7413860eb379b2f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 22 May 2012 12:23:06 +0200 Subject: [PATCH] added the possibility to translate the placeholder and title attributes in the PHP form templates (refs #4194) --- .../Twig/Resources/views/Form/form_div_layout.html.twig | 6 +++--- .../Resources/views/Form/widget_attributes.html.php | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig index 35ddc28b79..e26610f5d3 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig @@ -225,7 +225,7 @@ {% if required %} {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %} {% endif %} - {{ label|trans({}, translation_domain) }} + {{ label|trans({}, translation_domain) }} {% endspaceless %} {% endblock form_label %} @@ -305,14 +305,14 @@ {% block widget_attributes %} {% spaceless %} 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 %} - {% for attrname,attrvalue in attr %}{% if attrname in ['placeholder', 'title'] %}{{attrname}}="{{attrvalue|trans({}, translation_domain)}}" {% else %}{{attrname}}="{{attrvalue}}" {% endif %}{% endfor %} + {% for attrname, attrvalue in attr %}{% if attrname in ['placeholder', 'title'] %}{{ attrname }}="{{ attrvalue|trans({}, translation_domain) }}" {% else %}{{ attrname }}="{{ attrvalue }}" {% endif %}{% endfor %} {% endspaceless %} {% endblock widget_attributes %} {% block widget_container_attributes %} {% spaceless %} {% if id is not empty %}id="{{ id }}" {% endif %} - {% for attrname,attrvalue in attr %}{{attrname}}="{{attrvalue}}" {% endfor %} + {% for attrname, attrvalue in attr %}{{ attrname }}="{{ attrvalue }}" {% endfor %} {% endspaceless %} {% endblock widget_container_attributes %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget_attributes.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget_attributes.html.php index 043620725b..210b84cad5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget_attributes.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget_attributes.html.php @@ -5,5 +5,6 @@ name="escape($full_name) ?>" required="required" maxlength="escape($max_length) ?>" pattern="escape($pattern) ?>" - $v) { printf('%s="%s" ', $view->escape($k), $view->escape($v)); } ?> - + $v): ?> + escape($k), $view->escape(in_array($v, array('placeholder', 'title')) ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?> +