Vladimir Vladimir - 8 months ago 88
Twig Question

Symfony template generation via doctrine:crud

There Symfony project. He has

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

public function buildForm(FormBuilderInterface $builder, array $options)
->add('dOB', BirthdayType::class)

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


In your RecordType add

public function configureOptions(OptionsResolver $resolver)
            '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.