php - 使用 trans_default_domain 的 Symfony2 翻译

标签 php symfony translation

我想翻译不在我的 trans_default_domain 中的 twig 模板的一部分

例如:

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

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

编辑:

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

它在任何地方都有效,但当我尝试使用 trans_default_domain 获取我的 trans 时它不起作用

最佳答案

您将翻译存储在名为 messages.en.yml 的文件中这意味着根据 naming conventions for translations这些翻译的域为 messages而不是 ProjectMainBundle .

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

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

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

重命名后记得清除缓存。

关于php - 使用 trans_default_domain 的 Symfony2 翻译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19282031/

相关文章:

php - MYSQL,无法比较(等于)两个值

Symfony2 : Multi tenant roles in FosUserBundle

php - Symfony2 : Change choices with ajax and validation

ios - iOS是通过程序将本地化文本插入应用程序的正确方法是什么?

php - 无法在 nginx 上更改 `upload_max_filesize`

php - 如何解决 "Circular reference detected for service"问题?

view - Sonata AdminBundle 将字段显示为标签

dictionary - os x 自定义字典或自定义查找功能

php - 获取 MYSQL 结果为 key=>value 格式,尽管 key 不是字段名

PHPMyAdmin Designer 不显示关系