Ajouve
Ajouve

Reputation: 10089

Symfony2 Translation using trans_default_domain

I'd like to translate a part of my twig template which is not in my trans_default_domain

For exemple:

{% trans_default_domain 'FOSUserBundle' %}
{{ 'test.trans'|trans({}, 'ProjectMainBundle') }}

So test.trans is translated in ProjectMainBundle but I always have test.trans in my text.

Edit:

test.trans is in src/Project/MainBundle/Resources/translations/messages.en

It works everywhere but it doesn't work when I am trying to get my trans with a trans_default_domain

Upvotes: 4

Views: 9520

Answers (1)

Nicolai Fröhlich
Nicolai Fröhlich

Reputation: 52483

You are storing the translation in a file called messages.en.yml which means according to the naming conventions for translations these translations have the domain messages and not ProjectMainBundle.

Therefore the translator doesn't find a translation if you're trying to use the domain ProjectMainBundle and returns the string itself.

Each message file must be named according to the following path: domain.locale.loader

Your translations should be stored in @AcmeYourBundle/Resources/translations/<domain>.<locale>.yml ( or php, xliff, ... ).

Remember to clear your cache after renaming.

Upvotes: 7

Related Questions