-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Form labels force translation language #23611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
For reference, we're debating of a similar option for Intl form types in #23629. |
In case this will help someone: The way I do it now is actually overwriting the blocks, which I think it's a bit tricky: Inside the form: $builder
->add('firstName', TextType::class, [
'label' => 'first.name',
'label_attr' => ['translation_domain_language' => $this->language->getIso()],
]) Overwriting the twig file: {% block form_label %}
...
{% set translation_domain_language = '' %}
{% if label_attr.translation_domain_language is defined %}
{% set translation_domain_language = label_attr.translation_domain_language %}
{% endif %}
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
<span></span>{{ label|trans({}, translation_domain, translation_domain_language)|raw }}</label>
....
{% endblock form_label %} And for buttons I modify their specific block. |
What about implementing a tag like |
Is this really a common use case? I am not convinced we need to add support for it in the core. |
I am closing here as I do not think this is a very common use case and it should be easily solvable with a custom form theme overriding the |
In form class we have |
I have a situation where I have set a locale for my application but there is a form in a different language where I want to have the labels available in that language.
inside the
vendor\symfony\Symfony\src\Symfony\Bridge\Twig\Resources\views\Form\form_div_layout.html.twig
we haveblock form_label
. This block accepts translation key and the domain but no languageIn a normal situation I would use something like this in order to force the language:
In the form builder now we can do something like:
Would be of any use to add something like:
and to end up using inside the
block form_label
something like:The text was updated successfully, but these errors were encountered: