8000 {{ label }} translation in validation messages · Issue #39874 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
{{ label }} translation in validation messages #39874
Closed
@mmarton

Description

@mmarton

Symfony version(s) affected: 5.2.x
This feature was added Symfony 5.2 #35338

Description
Having label_format and translation_domain added in configureOptions doesn't have effect and the label in the message didn't get translated.

How to reproduce

# project.hu.yaml
form.title: cím
# validators.hu.yaml
"This value should not be blank.": "A {{ label }} megadása kötelező!"
// this way it's NOT working
class ProjectType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder->add('title', TextType::class ['validators' => new NotBlank()]);
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'label_format' => 'form.%name%',
            'translation_domain' => 'project',
        ]);
    }
}

// this way it IS working
class ProjectType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder->add('title', TextType::class, [
            'label_format' => 'form.%name%',
            'translation_domain' => 'project',
            'validators' => new NotBlank()
        ]);
    }
}

Expected: "A cím megadása kötelező!"
Got: "A Title megadása kötelező!" + missing translation of 'title' fom 'messages' domain

Possible Solution
Check the form options not just the field options when translating the label for validation messages

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

      0