Can’t change label for password field in registration form Symfony

I generated a registration form with Symfony’s console by running symfony console make:registration-form in a terminal. I am now trying to change the labels (the website is supposed to be in French), so here is what I did in FormRegistrationFormType.php:

class RegistrationFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('username', null, [
                'label' => 'Nom d'utilisateur'
            ])
            ->add('agreeTerms', CheckboxType::class, [
                'label' => 'Accepter les conditions générales',
                'mapped' => false,
                'constraints' => [
                    new IsTrue([
                        'message' => 'Vous devez accepter nos conditions générales.',
                    ]),
                ],
            ])
            ->add('plainPassword', PasswordType::class, [
                // instead of being set onto the object directly,
                // this is read and encoded in the controller
                'mapped' => false,
                'label' => 'Mot de passe',
                'constraints' => [
                    new NotBlank([
                        'message' => 'Veuillez entrer un mot de passe',
                    ]),
                    new Length([
                        'min' => 6,
                        'minMessage' => 'Votre mot de passe doit contenir au moins {{ limit }} caractères',
                        // max length allowed by Symfony for security reasons
                        'max' => 4096,
                    ]),
                ],
            ])
        ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => User::class,
        ]);
    }
}

However, if you look at the result below:

The result of the above code

…you will notice that the label for the "password" field is still "Password" and not "Mot de passe" as intended!
What am I doing wrong?

Additionally, I also want to change the big "Register" label, so here is what I did in my .html.twig file:

{% extends 'base.html.twig' %}

{% block title %}S'inscrire{% endblock %}

Here again it doesn’t work. What should I do?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *