gpt4 book ai didi

symfony - i18n 不适用于自定义错误页面

转载 作者:行者123 更新时间:2023-12-05 07:57:59 25 4
gpt4 key购买 nike

我已经在 app/Resources/TwigBundle/views/Exception 中为错误页面创建了模板。但是我对这些页面的翻译有疑问,即

<h3>{{ 'error_page.404.header'|trans({}, 'ProjCoreBundle') }}</h3>

不工作。我的翻译在 src/Proj/CoreBundle/Resources/translations/ProjCoreBundle.%lang%.yml 中,其中 %lang% 表示语言环境(即“en”)并且它们在其他页面上工作正常。什么可能会导致问题。

最佳答案

您需要在正确的目录中进行必要的覆盖。在这种情况下,在顶级目录 app/Resources/TwigBundle/translationsapp/Resources/translations 文件夹中(参见 http://symfony.com/doc/current/book/translation.html#translation-resource-file-names-and-locations )。

Symfony looks for message files (i.e. translations) in the following locations:

  • the app/Resources/translations directory;

  • the app/Resources//translations directory

  • the Resources/translations/ directory inside of any bundle.

这里列出了最高的位置 优先级第一。也就是说,您可以覆盖的翻译消息 前 2 个目录中的任何一个包。

要在您自己的包中使用另一个包的覆盖部分,您需要从第二个包继承您的包:参见 http://symfony.com/doc/current/cookbook/bundles/inheritance.html

class AcmeUserBundle extends Bundle
{
public function getParent()
{
return 'FOSUserBundle';
}
}

By making this simple change, you can now override several parts of the FOSUserBundle simply by creating a file with the same name.

此外,如果您使用的是 Symfony 2.5,请参阅此版本中引入的调试机制。

关于symfony - i18n 不适用于自定义错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25862527/

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