Symfony2 Translation using trans_default_domain

2019-06-26 08:38发布

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

1条回答
Juvenile、少年°
2楼-- · 2019-06-26 09:08

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.

查看更多
登录 后发表回答