Skip to content

[Translation] domain of TranslatableMessage ignored in Contraint/Length #62354

@ryckblick

Description

@ryckblick

Symfony version(s) affected

7.3

Description

When using a TranslatableMessage with an explicitly set domain in a Constraint/Length minMessage the passed domain is ignored and reset to 'validators'.

How to reproduce

class RegistrationFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ...
            ->add('plainPassword', PasswordType::class, [
                // ...
                'constraints' => [
                    // ...
                    new Length([
                        'min' => 8,
                        'minMessage' => new TranslatableMessage('registration.password.min', [], 'forms'),
                        'max' => 4096,
                    ]),
                ],
            ])
        ;
    }

forms.en.yaml

registration:
    password:
        min: 'Your password should be at least {{ limit }} characters'

WebProfiler shows, that Symfony is looking for 'registration.password.min' inside validators domain ignoring the set domain. If you put the same config in validators.en.yaml it works.

I use TranslatableMessage in other constraints aswell and there the passed domain is used.

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions