Skip to content

[Symfony] Validation errors for parameters using required isn't translated based on request locale #7336

@gremo

Description

@gremo

API Platform version(s) affected: 4.1.20

Description
When a parameter uses the built-in required attribute, validation errors are not translated, even though the request has the correct locale set. In my case, I've configured the framework to set the locale based on the Accept-Language header:

framework:
    set_locale_from_accept_language: true

I can dump the request locale in ParameterValidatorProvider and get the correct result.

Now, consider these two parameters: name uses Assert\NotBlank constraint, surname uses the required attribute:

parameters: [
    'name' => new QueryParameter(
        description: 'Nome della persona',
        constraints: [
            new Assert\NotBlank(),
        ]
    ),
    'surname' => new QueryParameter(
        description: 'Cognome della persona',
        required: true,
    ),
],

In the result error, name validation message is translated, the surname using required will be not:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions