Skip to content

Allow to pass parameters to fields translations #27698

@jeandonaldroselin

Description

@jeandonaldroselin

Description

This is an idea of improvement for the Form feature: allow passing parameters to the translated fields

In SF, the translation feature is available almost everywhere:

  • The Controllers ( Fully available )
  • The Twig ( Fully available )
  • The Services ( Fully available )
  • The Forms ( Partially available )

The translation feature is partially available in the SF Forms because we cannot translate the keys which are expecting parameters to be translated.


If the translation parameters would be available directly in the Form Classes,
the SF developers would have theses gains :

  • Be able to create SF Forms Fully Dynamic
  • Avoid duplicating some keys specific to the forms

Currently in the Twig templates there are two ways to display a SF Form :

1 - Integrate the fields manually One by One

2 - Integrate the fields dynamically by looping over each field of the form

I am using the second Method for the following reasons:

It is time consuming to integrate all the fields of a form manually ( one by one ) in twig template.

It is also time consuming to maintain a form if we have to touch two different layers (Twig+ Form Class) for each modification.

Example

-> This is French translation file : App.fr.yml

views:
      index:
            created_at: crée le %date%

-> This is my English Translation file : App.en.yml

views:
      index:
            created_at: created at %date%

-> This is my Form

...
            ->add('created', DateTimeType::class,
                array('label' => 'views.index.created_at',
                  'widget' => 'single_text',
                  'input' => 'datetime',
                  'format' => 'dd/MM/yyyy HH:mm',
                  'attr' => array('data-date-format' => 'DD-MM-YYYY HH:mm'),
                  'translation_domain' => 'App'));
  ...

-> This is my Twig template :

{% for key, field in form.children %}
       <div class="form-group form-md-line-input form-md-floating-label" id="block_{{ key }}">
           {{form_label(field)}}
           {{form_errors(field)}}
           {{form_widget(field)}}
        </div>
{% endfor %}

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