Search code examples
phpsymfonytranslationsymfony-formsmultilingual

How to translate symfony dropbox choices in the formtype


In the form generated by Symfony I would like to translate the child options, how can this be done?

        ->add('business', 'choice', array(
            'choices' => array('Zakelijk' => true, 'Prive' => false),
            'expanded' => true,
            'multiple' => false,
            'choices_as_values' => true,
        ))

I tried to include the standard symfony translation code directly in the code above, but then i get a php error.

$this->get('translator')->trans('business');

Solution

  • words.en.yml

    Zakelijk: Zakelijk
    Prive: Prive
    

    In your form:

    'translation_domain' => 'fooo'
    
    'choices' => array('Zakelijk' => true, 'Prive' => false),