Search code examples
phpformssymfonytranslate

Translate empty value in Symfony form


I have a form with select box, and that field has an empty value property. I want to have it translated but adding translation_domain doesn't change anything.

<?php

namespace Devell\HowFolderBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class NoteType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
    {
    $builder
        ->add('name', 'text')
        ->add('body', 'textarea');


    $categoryChoices = array();

    $builder->add('category', 'entity', array(
        'class'         => 'HowFolderBundle:Category',
        'empty_value'   => 'note.form.category.choose',
        'translation_domain' => 'HowFolderBundle'
    ));
    }

public function getName()
{
    return "note";
}
}

Solution

  • This should perfectely work as it's natively supported since > [Form] made it possible to translate the empty value of Choice fields.

    Then the problem is probably related to your translation configuration, Check if your Translation component is enabled and well configured.