Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 674
Ajouve Avatar asked Mar 22 '23 02:03

Ajouve


1 Answers

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.

like image 152
Nicolai Fröhlich Avatar answered Apr 02 '23 07:04

Nicolai Fröhlich