问题描述
我很难覆盖Symfony2的FOS用户捆绑包使用的标签.
I have a hard time overwriting labels that the FOS user bundle for Symfony2 uses.
我已经覆盖了Form类,但是"setOption"之类的元素没有选择,只有吸气剂.
I'm already overwriting the Form class, but there is no option for elements like "setOption", only getters.
我可以删除一个元素,然后用适当的标签再次添加它,但这似乎是一个过大的选择.可能有什么好的方法来覆盖表单元素上的选项,或者只是转换键吗?
I could just remove an element and than add it again with the proper label but this seems like an overkill. Is there any nice way of overwriting options on form elements, or just translation keys, perhaps?
推荐答案
您不需要覆盖Form类.
You don't need to overwrite Form classes.
在app/Resources/translations
目录中复制/粘贴vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/translations/FOSUserBundle.xx.yml
文件(具有相同的目录结构和相同的文件名),并重新定义翻译以方便使用.
Copy/paste vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/translations/FOSUserBundle.xx.yml
files in your app/Resources/translations
directory (with the same directory structure and the same file name) and redefine translations to your convenience.
edit:如@ mario-johnathan所述,覆盖翻译不属于bundle继承的一部分.参见 http://symfony.com/doc/current/cookbook/bundles/Override.html#translations 以获得官方文档
edit: As told by @mario-johnathan, overriding translations is not part of bundle inheritance. See http://symfony.com/doc/current/cookbook/bundles/override.html#translations for official documentation
这篇关于如何覆盖FOS用户捆绑包表单标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!