Discussion:
Form labels translation
Dmitry Bykadorov
2011-09-08 12:32:00 UTC
Permalink
Is there more elegant way to translate form labels? Now I'm using this
solution:

<p>
{{ form_errors(comment_form.author) }}
{{ form_label(comment_form.author, 'token.commentFormName') |
trans | raw }}
{{ form_widget(comment_form.author) }}
</p>

Seems like 'raw' filter not good solution, but when I remove them -
'trans' filter will escaping label's html:

&lt;label for="blogcommenttype_author" class=" required"&gt;Name&lt;/
label&gt;
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
Christophe COEVOET
2011-09-09 06:59:12 UTC
Permalink
Post by Dmitry Bykadorov
Is there more elegant way to translate form labels? Now I'm using this
<p>
{{ form_errors(comment_form.author) }}
{{ form_label(comment_form.author, 'token.commentFormName') |
trans | raw }}
{{ form_widget(comment_form.author) }}
</p>
Seems like 'raw' filter not good solution, but when I remove them -
Labels are already translated using the default group (i.e. /messages/)
in the theme. So simply provide the translations.
The great advantage is that what you ned to translate is only the label,
not the markup around it.
--
Christophe | Stof
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
Dmitry Bykadorov
2011-09-09 07:31:42 UTC
Permalink
Yes ) Markup translation is ugly solution.

Christophe, validation messages translated by the same way?
Post by Christophe COEVOET
Post by Dmitry Bykadorov
Is there more elegant way to translate form labels? Now I'm using this
<p>
     {{ form_errors(comment_form.author) }}
     {{ form_label(comment_form.author, 'token.commentFormName') |
trans | raw }}
     {{ form_widget(comment_form.author) }}
</p>
Seems like 'raw' filter not good solution, but when I remove them -
Labels are already translated using the default group (i.e. /messages/)
in the theme. So simply provide the translations.
The great advantage is that what you ned to translate is only the label,
not the markup around it.
--
Christophe | Stof
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
Ian Jamieson
2011-09-09 12:13:47 UTC
Permalink
The only difference I found for validation messages that had me scratching
my head for a while and searching the docs
was I needed to put validation messages to be translated in the "
validators" domain.
so the file with the translations was something like:
validators.<locale>.xliff
Post by Dmitry Bykadorov
Yes ) Markup translation is ugly solution.
Christophe, validation messages translated by the same way?
Post by Christophe COEVOET
Post by Dmitry Bykadorov
Is there more elegant way to translate form labels? Now I'm using this
<p>
{{ form_errors(comment_form.author) }}
{{ form_label(comment_form.author, 'token.commentFormName') |
trans | raw }}
{{ form_widget(comment_form.author) }}
</p>
Seems like 'raw' filter not good solution, but when I remove them -
Labels are already translated using the default group (i.e. /messages/)
in the theme. So simply provide the translations.
The great advantage is that what you ned to translate is only the label,
not the markup around it.
--
Christophe | Stof
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
Vladislav Rastrusny
2011-10-28 13:59:45 UTC
Permalink
Is it possible to fetch translation from custom group (domain), not
'messages'? I thought of providing 'label' option to *$builder->add()* call:

class EnquiryType extends AbstractType {

public function buildForm(FormBuilder $builder, array $options) {
$builder->add('name', null, array('label' => *<translation goes
here>*));


but I can't seem to find a good way of fetching translator service from an
AbstractType child.

And the default translation domain seem to be hardcoded in
form_div_layout.html.twig:

{% block generic_label %}
{% spaceless %}
{% if required %}
{% set attr = attr|merge({'class': attr.class|default('') ~ '
required'}) %}
{% endif %}
<label{% for attrname,attrvalue in attr %}
{{attrname}}="{{attrvalue}}"{% endfor %}>*{{ label|trans }}*</label>
{% endspaceless %}
{% endblock %}
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
Vladislav Rastrusny
2011-10-28 14:08:19 UTC
Permalink
It seems, that this is planned for 2.1

https://github.com/symfony/symfony/issues/1895
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
Loading...