8000 Form labels force translation language · Issue #23611 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

Closed
ghost opened this issue Jul 21, 2017 · 6 comments
Closed

Form labels force translation language #23611

ghost opened this issue Jul 21, 2017 · 6 comments

Comments

@ghost
Copy link
ghost commented Jul 21, 2017
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no
Symfony version all

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 have block form_label. This block accepts translation key and the domain but no language

`label : label|trans({}, translation_domain)`.

In a normal situation I would use something like this in order to force the language:

{{ translation.key | trans({}, 'messages', 'de') }}

In the form builder now we can do something like:

$builder
    ->add('field', TextType::class, [
        'label' => 'translation.key',
        'translation_domain' => 'messages',

Would be of any use to add something like:

$builder
    ->add('field', TextType::class, [
        'label' => 'translation.key',
        'translation_domain' => 'messages',
        'translation_domain_language' => 'de' //as language iso or whatever that can be passed from controller or other places

and to end up using inside the block form_label something like:

`label : label|trans({}, translation_domain, translation_domain_language)`.
@ogizanagi
Copy link
Contributor

For reference, we're debating of a similar option for Intl form types in #23629.

@ghost
Copy link
Author
ghost commented Jul 24, 2017

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.

@mvrhov
Copy link
mvrhov commented Jul 24, 2017

What about implementing a tag like trans_default_domain. But only for language

@xabbuh
Copy link
Member
xabbuh commented Nov 1, 2018

Is this really a common use case? I am not convinced we need to add support for it in the core.

@xabbuh
Copy link
Member
xabbuh commented Nov 12, 2018

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 form_label block.

@xabbuh xabbuh closed this as completed Nov 12, 2018
@raffcioo
Copy link

In form class we have configureOptions method where we can setDefaults so we can easly set e.g. 'translation_domain' which is nice. Why can't we have another option e.g. 'translation_locale'? to force that locale on translated labels... My app has multiple languages but admin module is only in one language which is not the default app's locale so I want to easly force that locale on that form labels having only one translation file (for now) and I can't? I need to create custom form theme? In Twig there is easy way to do it but in forms this is obviously missing feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0