AdamQuaileFieldsetBundle
AdamQuaileFieldsetBundle copied to clipboard
Automatic translation of legends
I have a form to which I pass a translation_domain as parameter.
Am I missing something or could it truely be that the legend titles won't be translated automatically?
To be honest, I've never tried it. Perhaps you could share some code and I can try and help. Also, which version of symfony are you using because it appears the recommended way of setting it changes slightly in 2.7?
http://stackoverflow.com/questions/18095592/symfony2-set-translation-domain-for-a-whole-form
Sure. As I work with a form that is not tied to an entity I just call (using Symfony 2.7)
$this->createFormBuilder(null, [ 'translation_domain' => $domain ])
->add('first', 'fieldset', [
'label' => false,
'legend' => 'form.first_fieldset', // is not translated and ignores translation domain
'fields' => [
[
'name' => 'first_name',
'type' => 'text',
'attr' => [
'label' => 'form.first_name' // is translated properly respecting translation domain
]
],
[
'name' => 'last_name',
'type' => 'text',
'attr' => [
'label' => 'form.last_name' / // is translated properly respecting translation domain
]
]
]
]);
Just saw that legend variable in fieldset.html.twig misses the trans modifier. Adding it (see the example beneath) makes translations work, but still ignores the passed translation domain.
{% block fieldset_widget %}
<fieldset {{ block('widget_container_attributes') }}>
{% if legend is defined and legend is not empty %}
<legend>{{ legend | trans }}</legend>
{% endif %}
{{ form_widget(form) }}
</fieldset>
{% endblock %}
I've never tried the translation domain using this bundle, but you could try setting translation_domain
in each attr
key as these will be passed to the underlying types.
You could also try creating a form class for this form and then setting it as a default option. http://stackoverflow.com/a/18096325