New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to pass parameters to fields translations #27698

Open
JeeDay opened this Issue Jun 24, 2018 · 2 comments

Comments

Projects
None yet
4 participants
@JeeDay

JeeDay commented Jun 24, 2018

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 %}
@webnet-fr

This comment has been minimized.

Contributor

webnet-fr commented Jun 29, 2018

+1 for this feature.

It would be very nice if there was a way to provide translation parameters for label and help optons.

We'd propose to add translation_parameters option to FormType field. We can make a PR to discuss the implementation.

@ro0NL

This comment has been minimized.

Contributor

ro0NL commented Sep 29, 2018

Related to #23611 which also asks for more translation options. Which made me think of #28635 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment