如何在 Twig 中制作全局域消息


How to make a global domain message in Twig

在我正在构建的 Web 应用程序中,有几条消息不是特定于捆绑包的。因此,我正在考虑将它们放在"app/Resources/translations/EPCommon.en.yml"中。

问题是我不知道如何在 Twig 中调用此域消息。我尝试了一些东西,但它不起作用。

title="{{'share.facebook'|trans()}}"
title="{{'share.facebook'|trans({}, 'EPCommon')}}"
Result : title="share.facebook"

有人可以告诉我我做错了什么吗?谢谢

编辑 :yml文件,以防其中有问题。

# app/Resources/translations/EPCommon.en.yml
share:
    facebook: "Share on Facebook"
    google: "Share on Google+"
    twitter: "Share on Twitter"
help:
    button: "Help"
好的,

我找到了解决方案!翻译目录似乎存储在文件名"/app/cache/dev/translations/catalogs.en.php"(用于"dev"环境/"en"区域设置)中。由于某种原因,即使在清除缓存后,我的EPCommon目录也不在那里。

所以我手动删除了"app/cache/dev"并让它重新生成,现在它可以工作了。

谢谢大家。