gpt4 book ai didi

php - 使用 trans_default_domain 的 Symfony2 翻译

转载 作者:可可西里 更新时间:2023-10-31 22:44:02 27 4
gpt4 key购买 nike

我想翻译不在我的 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com