Symfony2 entity field type: translate list items

I have a Symfony2 form with an entity field type with country codes. Now I want to translate each item of the field to show the name of the language in the language of the current users locale.

How can I translate the items?

         ->add('country', 'entity', array(
            'required'          => true,
            'property'          => 'countrycodeiso3166',
            'class'             => 'xxxDatabaseBundle:Country',
            'query_builder'     => function (EntityRepository $er) {
                return $er->createQueryBuilder('c')
                    ->orderBy('c.countrycodeiso3166', 'ASC');
            },
        ))

Thanks a lot!


Source: forms

Leave a Reply