symfony entityType在var中翻译choice_label

时间:2017-09-03 04:28:47

标签: symfony

如何在字符串中的var中翻译entityType字段的choice_label?

$builder->add('shippingAddress', EntityType::class, array(
                    'class'    => 'LilWorksStoreBundle:Address' ,
                    'choice_label' => function ($obj) {
                        return    "String to translate with " . $obj->getName()  ;
                    },
                    'query_builder' => function (EntityRepository $er) use ($customer) {
                        return $er->createQueryBuilder('a')
                            ->leftJoin('LilWorksStoreBundle:Customer', 'c', 'WITH', 'c.id = a.customer')
                            ->where('c.id = :id')
                            ->setParameter('id',$customer->getId())
                            ;
                    },
                    'required' => false ,
                    'mapped'=> true,
                    'expanded' => true ,
                    'multiple' => false,
                    'translation_domain' => 'my_translation'
                ));

1 个答案:

答案 0 :(得分:0)

尝试这种方式:

'choice_translation_domain' => 'my_translation'