Skip to content

PropertyTranslator does not work for nested models #775

@tQuant

Description

@tQuant
    class MainForm {
        public function __construct(
            #[Nested]
            public SubForm $sub,
        ) {
        }
    }


    class SubForm implements PropertyTranslatorProviderInterface {
        #[Trim]
        #[Length(min: 5, max: 30, skipOnEmpty: true)]
        public ?string $phone = null;
        public function getPropertyTranslator(): ?PropertyTranslatorInterface {
            return new ArrayPropertyTranslator([
                'phone' => 'Телефон',
            ]);
        }
    }

    $form = new MainForm(new SubForm());
    $form->sub->phone = '123';
    $resultMain = $validator->validate($form);
    $resultSub = $validator->validate($form->sub);

    echo json_encode([
        'main' => $resultMain->getErrorMessages(),
        'sub' => $resultSub->getErrorMessages(),
    ]);

In error messages for main model property name is not translated

{ "main":["Phone должно содержать как минимум 5 символов."], "sub":["Телефон должно содержать как минимум 5 символов."] }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions