简体   繁体   English

Symfony2-翻译实体字段类型选项

[英]Symfony2 - Translate entity field type options

I'm using the FormBuilder to create my form. 我正在使用FormBuilder创建表单。 That works fine. 很好 The problem is my "Licence Object" which creates an select field with options. 问题是我的“许可证对象”创建了一个带有选项的选择字段。 These options should be translated. 这些选项应进行翻译。 But how to do that? 但是该怎么做呢?

$form = $this   ->createFormBuilder($request)
                    ->add('title', 'text',
                        array(  'label' => $this->get('translator')->trans('form.title', array(), 'client_request_a_photo'))
                    )
                    ->add('description', 'textarea',
                        array(  'label' => $this->get('translator')->trans('form.description', array(), 'client_request_a_photo'))
                    )
                    ->add('licence','document',
                       array('class'=>'WunschbildBundle\Document\Licence', 'property'=>'options', 
                          'label' => $this->get('translator')->trans('form.licence', array(), 'client_request_a_photo'))
                    )                      
                    ->getForm();

In any case, you don't provide what is the 'document' field type, so we can't help much. 无论如何,您都不会提供“文档”字段类型,因此我们无济于事。 However, from what I understand the options are fetched through the attribute 'options' of the 'Licence' object. 但是,据我了解,这些选项是通过“许可证”对象的属性“选项”来获取的。 If you want those to be translated, the object 'Licence' must be translatable and the attribute 'options' must have translations. 如果要翻译它们,则对象“许可证”必须是可翻译的,并且属性“选项”必须具有翻译。 You can do this by using the doctrine extensions bundle. 您可以通过使用学说扩展包来实现。 The documentation about Translatable can be found here . 可以在此处找到有关Translatable的文档。 Hope this help. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM