gpt4 book ai didi

php - 从自定义目录加载 Symfony2 翻译

转载 作者:可可西里 更新时间:2023-11-01 13:30:22 24 4
gpt4 key购买 nike

众所周知,Symfony2 在这些目录中查找翻译:

YourBundle\Resources\translations\ - here lot of .yml files
app\Resources\translations\ - here lot of .yml files

但是如果我想将我的翻译放入

MyBundle\Resources\translations\2015_04_23\- 许多 .yml 文件将放在此处

我阅读了文档但没有看到解决方案,这可能吗?也许我省略了部分文档?有人可以帮我吗?谢谢!

最佳答案

确实,这里记录了它:http://symfony.com/doc/current/components/translation/custom_formats.html#components-translation-custom-loader

您的操作与文档中的完全相同,但是当您使用翻译加载器时,您可以通过选择自己的目录来添加翻译:

$translator->addResource('my_format', __DIR__.'/translations/messages.txt', 'fr_FR');

(只需将 __DIR__ 替换为您明智选择的目录,例如,如果您使用动态文件,请务必小心:例如,您应该使用服务来确保您的代码将被易于维护)

关于php - 从自定义目录加载 Symfony2 翻译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29822102/

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