Skip to content

[Form] Document using TranslatableMessage for label and choice_label #16717

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

Merged
merged 1 commit into from
Jun 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions reference/forms/types/options/choice_label.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ more control::

// or if you want to translate some key
//return 'form.choice.'.$key;
//return new TranslatableMessage($key, false === $choice ? [] : ['%status%' => $value], 'store');
},
]);

Expand Down
20 changes: 18 additions & 2 deletions reference/forms/types/options/label.rst.inc
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
``label``
~~~~~~~~~

**type**: ``string`` **default**: The label is "guessed" from the field name
**type**: ``string`` or ``TranslatableMessage`` **default**: The label is "guessed" from the field name

Sets the label that will be used when rendering the field. Setting to ``false``
will suppress the label. The label can also be set in the template:
will suppress the label.

use Symfony\Component\Translation\TranslatableMessage;

$builder
->add('zipCode', null, [
'label' => 'The ZIP/Postal code',
])

// ...

->add('zipCode', null, [
'label' => new TranslatableMessage('address.zipCode', ['%country%' => $country], 'address'),
])
;

The label can also be set in the template:

.. configuration-block::

Expand Down