Skip to content

[TwigComponent] Scope of translation domains #2047

Open
@CMH-Benny

Description

@CMH-Benny

There is something unexpected going on with scopes in twig UX components, when it comes to translation domains.
Let's assume there is a template foo.html.twig and it uses a component twig:Bar that allows to pass content to it:

{% trans_default_domain "foo" %}
<div class="content">
  <p>{{ "foo.whatever"|trans }}
  <twig:Bar baz="bla">
    <p>{{ 'foo.bar'|trans }}</p> {# |trans will use default "messages" domain here and not "foo" that I declared in this template #}
  </twig:Bar>
</div>

To make it work, I have to do:

{% trans_default_domain "foo" %}
<div class="content">
  <p>{{ "foo.whatever"|trans }}
  <twig:Bar baz="bla">
    {% trans_default_domain "foo" %}
    <p>{{ 'foo.bar'|trans }}</p> {# |trans will now use "foo" domain correctly #}
  </twig:Bar>
</div>

Is that intended? If you want to render multiple twig:Bar and have to repeat the setting again and again. You also don't necessarily want to put it inside of the template of the component, because it might be used in another outer template where the content uses texts from another translation domain. Is there a way to avoid that, because it's pretty unintuitive.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions