Skip to content

[Form] deprecate translation_parameters options given TranslatableMessage #42077

@Tobion

Description

@Tobion

Description
With the introduction of TranslatableMessage in #37670 (https://symfony.com/blog/new-in-symfony-5-2-translatable-objects) and being able to use this in form label and help in #41717, it makes all the translation_parameters options kind of obsolete and duplicates alot of functionality. So we should make sure that TranslatableMessage can be used in all relevant form options and then we should deprecate

The translation_domain option can likely be kept as it also serves as a way to disable translation and uses domain inheritance.

Example https://symfony.com/doc/current/reference/forms/types/choice.html#choice-translation-parameters

before:

$builder->add('id', null, [
    'choices' => [
        'form.order.yes' => true,
        'form.order.no' => false,
    ],
    'choice_translation_parameters' => function ($choice, $key, $value) {
        if (false === $choice) {
            return [];
        }

        return ['%company%' => 'ACME Inc.']
    },
]);

could be achieved with:

$builder->add('id', null, [
    'choices' => [
        'form.order.yes' => true,
        'form.order.no' => false,
    ],
    'choice_label' => function ($choice, $key, $value) {
        return new TranslatableMessage($key, false === $choice ? [] : ['%company%' => 'ACME Inc.']);
    },
]);

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy