-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Form] New translation_parameters option #10065
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
javiereguiluz
merged 7 commits into
symfony:master
from
webnet-fr:form_translation_parameters
Mar 6, 2019
+504
−2
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c57d30a
new translation_parameters form option
webnet-fr 32e79e1
correct link error
webnet-fr a655106
confirm with 28635
71fc7ce
typo in form_translation_parameters docs
d7e7b0b
correct attr link in entity type doc
70f36ad
correct bug
20c6f5a
correct arrays short syntax
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ A simple, non-responsive button. | |
| options | - `disabled`_ | | ||
| | - `label`_ | | ||
| | - `translation_domain`_ | | ||
| | - `label_translation_parameters`_ | | ||
| | - `attr_translation_parameters`_ | | ||
+----------------------+----------------------------------------------------------------------+ | ||
| Parent type | none | | ||
+----------------------+----------------------------------------------------------------------+ | ||
|
@@ -51,3 +53,83 @@ as a key. This can be useful when you need to set a custom class for the button: | |
.. include:: /reference/forms/types/options/button_label.rst.inc | ||
|
||
.. include:: /reference/forms/types/options/button_translation_domain.rst.inc | ||
|
||
label_translation_parameters | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
**type**: ``array`` **default**: ``array()`` | ||
|
||
Translated `label`_ can contain | ||
:ref:`placeholders <component-translation-placeholders>`. | ||
This option allows you to pass an array of parameters in order to replace | ||
placeholders with actual values. | ||
|
||
Given this translation message: | ||
|
||
.. code-block:: yaml | ||
|
||
# translations/messages.en.yml | ||
form.order.submit_to_company: Send an order to %company% | ||
|
||
you can specify placeholder value: | ||
|
||
.. code-block:: php | ||
|
||
use Symfony\Component\Form\Extension\Core\Type\ButtonType; | ||
// ... | ||
|
||
$builder->add('send', ButtonType::class, array( | ||
'label' => 'form.order.submit_to_company', | ||
'label_translation_parameters' => array( | ||
'%company%' => 'ACME Inc.', | ||
), | ||
)); | ||
|
||
Note that `label_translation_parameters` of buttons are merged with those of its | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. double "`" are needed in ReST. |
||
parent. In other words the parent's translation parameters are available for | ||
children's buttons but can be overriden: | ||
|
||
.. code-block:: php | ||
|
||
// App/Controller/OrderController.php | ||
use App\Form\OrderType; | ||
// ... | ||
|
||
$form = $this->createForm(OrderType::class, $order, array( | ||
// available to all children, grandchildren and so on. | ||
'label_translation_parameters' => array( | ||
'%company%' => 'ACME', | ||
), | ||
)); | ||
|
||
.. code-block:: php | ||
|
||
// App/Form/OrderType.php | ||
use Symfony\Component\Form\Extension\Core\Type\ButtonType; | ||
// ... | ||
|
||
$builder->add('send', ButtonType::class, array( | ||
'label' => 'form.order.submit_to_company', | ||
// Value of parent's 'label_translation_parameters' will be merged with | ||
// this field's empty 'label_translation_parameters'. | ||
// array('%company%' => 'ACME') will be used to translate this label. | ||
)); | ||
|
||
.. code-block:: php | ||
|
||
// App/Form/OrderType.php | ||
use Symfony\Component\Form\Extension\Core\Type\ButtonType; | ||
// ... | ||
|
||
$builder->add('send', ButtonType::class, array( | ||
'label' => 'form.order.submit_to_company', | ||
'label_translation_parameters' => array( | ||
'%company%' => 'American Company Making Everything', | ||
), | ||
// Value of parent's 'label_translation_parameters' will be merged with | ||
// this button's 'label_translation_parameters'. | ||
// array('%company%' => 'American Company Making Everything') | ||
// will be used to translate this label. | ||
)); | ||
|
||
.. include:: /reference/forms/types/options/attr_translation_parameters.rst.inc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
reference/forms/types/options/attr_translation_parameters.rst.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
attr_translation_parameters | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
**type**: ``array`` **default**: ``array()`` | ||
|
||
Some translated `attr`_ (``title`` and ``placeholder``) can | ||
contain :ref:`placeholders <component-translation-placeholders>`. | ||
This option allows you to pass an array of parameters in order to replace | ||
placeholders with actual values. | ||
|
||
Given this translation message: | ||
|
||
.. code-block:: yaml | ||
|
||
# translations/messages.en.yml | ||
form.order.id.placeholder: Enter unique identifier of the order to %company% | ||
form.order.id.title: This will be the reference in communications with %company% | ||
|
||
you can specify placeholder value: | ||
|
||
.. code-block:: php | ||
|
||
$builder->add('id', null, array( | ||
'attr' => array( | ||
'placeholder' => 'form.order.id.placeholder', | ||
'title' => 'form.order.id.title', | ||
), | ||
'attr_translation_parameters' => [ | ||
'%company%' => 'ACME Inc.' | ||
] | ||
)); | ||
|
||
Note that `attr_translation_parameters` of children fields are merged with those | ||
of its parent. In other words the parent's translation parameters are available | ||
for children but can be overriden: | ||
|
||
.. code-block:: php | ||
|
||
// App/Controller/OrderController.php | ||
use App\Form\OrderType; | ||
// ... | ||
|
||
$form = $this->createForm(OrderType::class, $order, array( | ||
// available to all children, grandchildren and so on. | ||
'attr_translation_parameters' => array( | ||
'%company%' => 'ACME', | ||
), | ||
)); | ||
|
||
.. code-block:: php | ||
|
||
// App/Form/OrderType.php | ||
// ... | ||
|
||
$builder->add('id', null, array( | ||
'attr' => array( | ||
'placeholder' => 'form.order.id.placeholder', | ||
'title' => 'form.order.id.title', | ||
), | ||
// Value of parent's 'attr_translation_parameters' will be merged with | ||
// this field's empty 'attr_translation_parameters'. | ||
// array('%company%' => 'ACME') will be used to translate 'placeholder' and 'title'. | ||
)); | ||
|
||
.. code-block:: php | ||
|
||
// App/Form/OrderType.php | ||
// ... | ||
|
||
$builder->add('id', null, array( | ||
'attr' => array( | ||
'placeholder' => 'form.order.id.placeholder', | ||
'title' => 'form.order.id.title', | ||
), | ||
'attr_translation_parameters' => array( | ||
'%company%' => 'American Company Making Everything', | ||
), | ||
// Value of parent's 'attr_translation_parameters' will be merged with | ||
// this field's 'attr_translation_parameters'. | ||
// array('%company%' => 'American Company Making Everything') | ||
// will be used to translate 'placeholder' and 'title'. | ||
)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
reference/forms/types/options/help_translation_parameters.rst.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
help_translation_parameters | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
**type**: ``array`` **default**: ``array()`` | ||
|
||
Translated `help`_ can | ||
contain :ref:`placeholders <component-translation-placeholders>`. | ||
This option allows you to pass an array of parameters in order to replace | ||
placeholders with actual values. | ||
|
||
Given this translation message: | ||
|
||
.. code-block:: yaml | ||
|
||
# translations/messages.en.yml | ||
form.order.id.help: This will be the reference in communications with %company% | ||
|
||
you can specify placeholder value: | ||
|
||
.. code-block:: php | ||
|
||
$builder->add('id', null, array( | ||
'help' => 'form.order.id.help', | ||
'help_translation_parameters' => [ | ||
'%company%' => 'ACME Inc.' | ||
] | ||
)); | ||
|
||
Note that `help_translation_parameters` of children fields are merged with those | ||
of its parent. In other words the parent's translation parameters are available | ||
for children but can be overriden: | ||
|
||
.. code-block:: php | ||
|
||
// App/Controller/OrderController.php | ||
use App\Form\OrderType; | ||
// ... | ||
|
||
$form = $this->createForm(OrderType::class, $order, array( | ||
// available to all children, grandchildren and so on. | ||
'help_translation_parameters' => array( | ||
'%company%' => 'ACME', | ||
), | ||
)); | ||
|
||
.. code-block:: php | ||
|
||
// App/Form/OrderType.php | ||
// ... | ||
|
||
$builder->add('id', null, array( | ||
'help' => 'form.order.id.help', | ||
// Value of parent's 'help_translation_parameters' will be merged with | ||
// this field's empty 'help_translation_parameters'. | ||
// array('%company%' => 'ACME') will be used to translate 'help'. | ||
)); | ||
|
||
.. code-block:: php | ||
|
||
// App/Form/OrderType.php | ||
// ... | ||
|
||
$builder->add('id', null, array( | ||
'help' => 'form.order.id.help', | ||
'help_translation_parameters' => array( | ||
'%company%' => 'American Company Making Everything', | ||
), | ||
// Value of parent's 'help_translation_parameters' will be merged with | ||
// this field's 'help_translation_parameters'. | ||
// array('%company%' => 'American Company Making Everything') | ||
// will be used to translate 'help'. | ||
)); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are now using
[]
for arrays. This should be changed everywhere in this pull request.