Skip to content

Commit b0e5760

Browse files
committed
feature #28635 [Form] Add label_translation_parameters, help_translation_parameters and attr_translation_parameters options to base form type (webnet-fr)
This PR was squashed before being merged into the 4.3-dev branch (closes #28635). Discussion ---------- [Form] Add label_translation_parameters, help_translation_parameters and attr_translation_parameters options to base form type | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes. Travis-ci isn't green because it tests the components separately. Fabbot.io requires license headers in files where they were not present before. | Fixed tickets | #27698 | License | MIT | Doc PR | symfony/symfony-docs#10065 Hi, this is an alternative to #27775. `translation_parameters` is separated to `label_translation_parameters`, `help_translation_parameters`, `attr_translation_parameters`. Commits ------- b3f3c5361f [Form] Add label_translation_parameters, help_translation_parameters and attr_translation_parameters options to base form type
2 parents 206bcda + fd94248 commit b0e5760

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

Resources/views/Form/bootstrap_3_layout.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@
187187
{%- endif -%}
188188
{%- else -%}
189189
{%- if help_html is same as(false) -%}
190-
{{- help|trans({}, translation_domain) -}}
190+
{{- help|trans(help_translation_parameters, translation_domain) -}}
191191
{%- else -%}
192-
{{- help|trans({}, translation_domain)|raw -}}
192+
{{- help|trans(help_translation_parameters, translation_domain)|raw -}}
193193
{%- endif -%}
194194
{%- endif -%}
195195
</span>

Resources/views/Form/bootstrap_4_layout.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219
{% set label = name|humanize %}
220220
{%- endif -%}
221221
{%- endif -%}
222-
<{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}{% block form_label_errors %}{{- form_errors(form) -}}{% endblock form_label_errors %}</{{ element|default('label') }}>
222+
<{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ translation_domain is same as(false) ? label : label|trans(label_translation_parameters, translation_domain) }}{% block form_label_errors %}{{- form_errors(form) -}}{% endblock form_label_errors %}</{{ element|default('label') }}>
223223
{%- else -%}
224224
{%- if errors|length > 0 -%}
225225
<div id="{{ id }}_errors" class="mb-2">
@@ -312,9 +312,9 @@
312312
{%- endif -%}
313313
{%- else -%}
314314
{%- if help_html is same as(false) -%}
315-
{{- help|trans({}, translation_domain) -}}
315+
{{- help|trans(help_translation_parameters, translation_domain) -}}
316316
{%- else -%}
317-
{{- help|trans({}, translation_domain)|raw -}}
317+
{{- help|trans(help_translation_parameters, translation_domain)|raw -}}
318318
{%- endif -%}
319319
{%- endif -%}
320320
</small>

Resources/views/Form/form_div_layout.html.twig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@
232232
{% set label = name|humanize %}
233233
{%- endif -%}
234234
{%- endif -%}
235-
<button type="{{ type|default('button') }}" {{ block('button_attributes') }}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}</button>
235+
<button type="{{ type|default('button') }}" {{ block('button_attributes') }}>{{ translation_domain is same as(false) ? label : label|trans(label_translation_parameters, translation_domain) }}</button>
236236
{%- endblock button_widget -%}
237237

238238
{%- block submit_widget -%}
@@ -279,7 +279,7 @@
279279
{%- if translation_domain is same as(false) -%}
280280
{{- label -}}
281281
{%- else -%}
282-
{{- label|trans({}, translation_domain) -}}
282+
{{- label|trans(label_translation_parameters, translation_domain) -}}
283283
{%- endif -%}
284284
</{{ element|default('label') }}>
285285
{%- endif -%}
@@ -301,9 +301,9 @@
301301
{%- endif -%}
302302
{%- else -%}
303303
{%- if help_html is same as(false) -%}
304-
{{- help|trans({}, translation_domain) -}}
304+
{{- help|trans(help_translation_parameters, translation_domain) -}}
305305
{%- else -%}
306-
{{- help|trans({}, translation_domain)|raw -}}
306+
{{- help|trans(help_translation_parameters, translation_domain)|raw -}}
307307
{%- endif -%}
308308
{%- endif -%}
309309
</p>
@@ -433,7 +433,7 @@
433433
{%- for attrname, attrvalue in attr -%}
434434
{{- " " -}}
435435
{%- if attrname in ['placeholder', 'title'] -%}
436-
{{- attrname }}="{{ translation_domain is same as(false) ? attrvalue : attrvalue|trans({}, translation_domain) }}"
436+
{{- attrname }}="{{ translation_domain is same as(false) ? attrvalue : attrvalue|trans(attr_translation_parameters, translation_domain) }}"
437437
{%- elseif attrvalue is same as(true) -%}
438438
{{- attrname }}="{{ attrname }}"
439439
{%- elseif attrvalue is not same as(false) -%}

Tests/Extension/Fixtures/StubTranslator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ class StubTranslator implements TranslatorInterface
1717
{
1818
public function trans($id, array $parameters = [], $domain = null, $locale = null)
1919
{
20-
return '[trans]'.$id.'[/trans]';
20+
return '[trans]'.strtr($id, $parameters).'[/trans]';
2121
}
2222
}

Tests/Extension/Fixtures/templates/form/custom_widgets.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
{% if label is empty %}
1212
{% set label = name|humanize %}
1313
{% endif %}
14-
<label>Custom label: {{ label|trans({}, translation_domain) }}</label>
14+
<label>Custom label: {{ label|trans(label_translation_parameters, translation_domain) }}</label>
1515
{% endspaceless %}
1616
{% endblock _names_entry_label %}
1717

@@ -20,6 +20,6 @@
2020
{% if label is empty %}
2121
{% set label = name|humanize %}
2222
{% endif %}
23-
<label>Custom name label: {{ label|trans({}, translation_domain) }}</label>
23+
<label>Custom name label: {{ label|trans(label_translation_parameters, translation_domain) }}</label>
2424
{% endspaceless %}
2525
{% endblock _name_c_entry_label %}

0 commit comments

Comments
 (0)