Vladimir Vladimir - 4 months ago 21
Twig Question

Symfony template generation via doctrine:crud

There Symfony project. He has

Entity/Record.php
With the command

php bin/console generate:doctrine:crud --entity=AppBundle:Record


Create a controller and a template. It seems to be nothing but one of the templates generated to create a new recording.

{{ form_start(form) }}
{{ form_widget(form) }}
<input type="submit" value="Create" />
{{ form_end(form) }}


Create a form in the controller

$record = new Record();
$form = $this->createForm('AppBundle\Form\RecordType', $record);


Create a form in
Form/RecordType.php


public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name')
->add('surname')
->add('patronymic')
->add('dOB', BirthdayType::class)
->add('phone')
;
}


The form of work, all input fields are there, but the name in front of input fields, both logical and should have be generated - it attribute Entity object. But they are in English, which is inconvenient for the user (see. Screenshot). How do I display them in Russian?

enter image description here

Answer

In your RecordType add

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults(
        array(
            'translation_domain' => 'forms'
        )
    );
}

and then create forms.ru.yml in app/Resources/translations/ clear cache so new translation file is detected (important) and you can write translations by

# forms.ru.yml
Name: Имя
Surname: Фамилия
Phone: Телефон

Above I assume your locale is set to ru if it's not then you will need to adjust file name.