From 4133fe085be237d9ad438ce64b0a590525c73820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 3 Oct 2015 15:22:41 +0200 Subject: [PATCH 1/6] synchronize comment with the current behavior After reading the compiler pass that applies the default translator strategy, I'm under the impression that the default actually is the native translator strategy. --- Resources/config/core.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/config/core.xml b/Resources/config/core.xml index 466845c780..26cc938a45 100644 --- a/Resources/config/core.xml +++ b/Resources/config/core.xml @@ -33,7 +33,7 @@ - + From 92f24a005c776ea6e6571e078c520b4a59818241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 3 Oct 2015 16:16:53 +0200 Subject: [PATCH 2/6] describe the underlying interface --- Resources/doc/reference/translation.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Resources/doc/reference/translation.rst b/Resources/doc/reference/translation.rst index c09eb616ec..8d0ba6fa86 100644 --- a/Resources/doc/reference/translation.rst +++ b/Resources/doc/reference/translation.rst @@ -134,6 +134,14 @@ labels are generated by using a simple rule: isValid => Is Valid +A label translator strategy processes labels so that they can follow a given +naming policy. It implements +``Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface``, which +consists of one method, with the following signature : +``public function getLabel($label, $context = '', $type = '');``. In the context +of a form with an ``isValid`` field, it is called as follows : +``$strategy->getLabel('isValid', 'form', 'label')`` + The ``AdminBundle`` comes with different key label generation strategies: From b08ab03d3a4c36bdf71452c89969de9b211c3195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 3 Oct 2015 16:18:33 +0200 Subject: [PATCH 3/6] use definition lists It is the use case for definition lists. --- Resources/doc/reference/translation.rst | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Resources/doc/reference/translation.rst b/Resources/doc/reference/translation.rst index 8d0ba6fa86..375f766226 100644 --- a/Resources/doc/reference/translation.rst +++ b/Resources/doc/reference/translation.rst @@ -145,15 +145,20 @@ of a form with an ``isValid`` field, it is called as follows : The ``AdminBundle`` comes with different key label generation strategies: -* ``sonata.admin.label.strategy.native``: DEFAULT - Makes the string human readable - ``isValid`` => ``Is Valid`` -* ``sonata.admin.label.strategy.form_component``: The default behavior from the Form Component - ``isValid`` => ``Isvalid`` -* ``sonata.admin.label.strategy.underscore``: Changes the name into a token suitable - for translation by prepending "form.label" to an underscored version of the field name +``sonata.admin.label.strategy.native`` + DEFAULT - Makes the string human readable ``isValid`` => ``Is Valid`` + +``sonata.admin.label.strategy.form_component`` + The default behavior from the Form Component + ``isValid`` => ``Isvalid`` + +``sonata.admin.label.strategy.underscore`` + Changes the name into a token suitable for translation by prepending + "form.label" to an underscored version of the field name. ``isValid`` => ``form.label_is_valid`` -* ``sonata.admin.label.strategy.noop``: does not alter the string - ``isValid`` => ``isValid`` + +``sonata.admin.label.strategy.noop`` + does not alter the string ``isValid`` => ``isValid`` ``sonata.admin.label.strategy.underscore`` will be better for i18n applications and ``sonata.admin.label.strategy.native`` will be better for native (single) language From 788b92703e318865a6f82f0ba9791756c54cc5cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 3 Oct 2015 16:19:51 +0200 Subject: [PATCH 4/6] document bc label translator strategy --- Resources/doc/reference/translation.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Resources/doc/reference/translation.rst b/Resources/doc/reference/translation.rst index 375f766226..29f6e248b4 100644 --- a/Resources/doc/reference/translation.rst +++ b/Resources/doc/reference/translation.rst @@ -160,6 +160,12 @@ The ``AdminBundle`` comes with different key label generation strategies: ``sonata.admin.label.strategy.noop`` does not alter the string ``isValid`` => ``isValid`` +``sonata.admin.label.strategy.bc`` + Backwards-Compatible label translator strategy. Labels are as they where + before label translator strategies where introduced. + ``isValid`` => ``Isvalid`` + Avoid it if you are creating a new project. + ``sonata.admin.label.strategy.underscore`` will be better for i18n applications and ``sonata.admin.label.strategy.native`` will be better for native (single) language apps based on the field name. It is reasonable to start with the ``native`` strategy From 0810a52e4ae9ed5a2e8d8c8ca81afbd0741f1298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 3 Oct 2015 16:20:05 +0200 Subject: [PATCH 5/6] add call for contributions --- Resources/doc/reference/translation.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Resources/doc/reference/translation.rst b/Resources/doc/reference/translation.rst index 29f6e248b4..550afda499 100644 --- a/Resources/doc/reference/translation.rst +++ b/Resources/doc/reference/translation.rst @@ -172,6 +172,9 @@ apps based on the field name. It is reasonable to start with the ``native`` stra and then, when the application needs to be translated using generic keys, the configuration can be switched to ``underscore``. +If you cannot find a strategy that fits your use case, you can easily implement +and use your own. If you do, consider contributing your strategy. + The strategy can be quickly configured when the Admin class is registered in the Container: From b4e748280fb87da8ea6b0a7475c083ee59f2bb96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 3 Oct 2015 15:48:43 +0200 Subject: [PATCH 6/6] expose the global label translator strategy Closes #2419 When people configure this, they probably want to do it on a global basis rather than for each of their admins. --- .../doc/reference/action_create_edit.rst | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Resources/doc/reference/action_create_edit.rst b/Resources/doc/reference/action_create_edit.rst index fa41134497..cd2e4b4e9f 100644 --- a/Resources/doc/reference/action_create_edit.rst +++ b/Resources/doc/reference/action_create_edit.rst @@ -22,6 +22,26 @@ To do: - options available when adding fields, inc custom templates - link to the field_types document for more details about specific field types +Global options +~~~~~~~~~~~~~~ + +There are some options about create and edit actions you might want to set +globally rather than on an admin-by-admin basis. This can done with the bundle +configuration. + +.. code-block:: yaml + + sonata_admin: + options: + label_translator_strategy: sonata.admin.label.strategy.native + +``options.label_translator_strategy`` + Defaults to ``sonata.admin.label.strategy.native``. The value should be the + id of a service that implements + ``Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface``. For + more information, see + `the dedicated document `_ + FormGroup options ~~~~~~~~~~~~~~~~~