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 @@ - + 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 ~~~~~~~~~~~~~~~~~ diff --git a/Resources/doc/reference/translation.rst b/Resources/doc/reference/translation.rst index c09eb616ec..550afda499 100644 --- a/Resources/doc/reference/translation.rst +++ b/Resources/doc/reference/translation.rst @@ -134,18 +134,37 @@ 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: -* ``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.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 @@ -153,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: