Skip to content

Commit b1fd71a

Browse files
Add choice_translation_parameters option
1 parent ec43b0c commit b1fd71a

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

reference/forms/types/choice.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ To use this field, you must specify *either* ``choices`` or ``choice_loader`` op
1818
| | - `choice_label`_ |
1919
| | - `choice_loader`_ |
2020
| | - `choice_name`_ |
21+
| | - `choice_translation_parameters`_ |
2122
| | - `choice_translation_domain`_ |
2223
| | - `choice_value`_ |
2324
| | - `expanded`_ |
@@ -225,6 +226,8 @@ correct types will be assigned to the model.
225226

226227
.. include:: /reference/forms/types/options/choice_name.rst.inc
227228

229+
.. include:: /reference/forms/types/options/choice_translation_parameters.rst.inc
230+
228231
.. include:: /reference/forms/types/options/choice_translation_domain.rst.inc
229232

230233
.. include:: /reference/forms/types/options/choice_value.rst.inc
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
choice_translation_parameters
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
**type**: ``array`` **default**: ``[]``
5+
6+
The choice values are translated before displaying it, so it can contain
7+
:ref:`translation placeholders <component-translation-placeholders>`.
8+
This option defines the values used to replace those placeholders.
9+
10+
Given this translation message:
11+
12+
.. code-block:: yaml
13+
14+
# translations/messages.en.yaml
15+
form.order.yes: 'I confirm my order to the company %company%'
16+
form.order.no: 'I cancel my order to the company %company%'
17+
18+
You can specify the placeholder values as follows::
19+
20+
$builder->add('id', null, [
21+
'choice' => [
22+
'form.order.yes' => true,
23+
'form.order.no' => false,
24+
],
25+
'choice_translation_parameters' => [
26+
'%company%' => 'ACME Inc.',
27+
],
28+
]);
29+
30+
The ``choice_translation_parameters`` option of children fields is merged with
31+
the same option of their parents, so children can reuse and/or override any of
32+
the parent placeholders.

0 commit comments

Comments
 (0)