twig dynamic translation domain

Viewed 22

I'm trying to translate user content, using a translation domain depending on the role of the user.

here is my code:

{% if is_granted('ROLE_TEACHER') %}
    {% set translation_domain = 'ROLE_TEACHER' %}
{% else %}
    {% set translation_domain = 'ROLE_PARENT' %}
{% endif %}

<h5>{{"Main Title"|trans({}, translation_domain) }}</h5>

This works perfect for a user, in browser. However the command for generating the translations (bin/console translation:extract en) generates them for the 'undefined' translation domain.

Is there a better way? Any ideas? Whats the standard way for doing this? I cant seem to find any docs.

0 Answers
Related