Symfony2 翻译使用 trans_default_domain [英] Symfony2 Translation using trans_default_domain

查看:32
本文介绍了Symfony2 翻译使用 trans_default_domain的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想翻译不在我的 trans_default_domain

例如:

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

所以 test.trans 在 ProjectMainBundle 中被翻译,但我的文本中总是有 test.trans.

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

test.trans 位于 src/Project/MainBundle/Resources/translations/messages.en

它在任何地方都可以使用,但是当我尝试使用 trans_default_domain

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

推荐答案

您将翻译存储在名为 messages.en.yml 的文件中,这意味着根据 翻译命名约定 这些翻译具有域messages 而不是 ProjectMainBundle.

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.

因此,如果您尝试使用域 ProjectMainBundle 并返回字符串本身,则翻译器不会找到翻译.

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

每个消息文件必须按照以下路径命名:domain.locale.loader

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

您的翻译应存储在 @AcmeYourBundle/Resources/translations/..yml(或 php、xliff、...)中.

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

记得在重命名后清除缓存.

Remember to clear your cache after renaming.

这篇关于Symfony2 翻译使用 trans_default_domain的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆