Skip to content

Commit

Permalink
Document the label translator strategy feature
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Oct 3, 2015
1 parent 185e454 commit 2af497a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions Resources/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Reference Guide
reference/action_delete
reference/action_export
reference/saving_hooks
reference/label_translator_strategy
reference/form_types
reference/form_help_message
reference/field_types
Expand Down
39 changes: 39 additions & 0 deletions Resources/doc/reference/label_translator_strategy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Label translator strategy
=========================

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')``

Several built-in label translator strategies are available.

``sonata.admin.label.strategy.bc``
Backwards-Compatible label translator strategy. Labels are as they where
before label translator strategies where introduced. The above call will
produce ``Isvalid``. Avoid it if you are creating a new project.

``sonata.admin.label.strategy.native``
This is the default. It tries to humanize the given label. The above call
will produce ``Is Valid``.

``sonata.admin.label.strategy.noop``
You guessed it, this one does nothing.

``sonata.admin.label.strategy.underscore``
This is the strategy you should use if you use Symfony's i18n features. The
above call will produce ``form.label_is_valid``. When testing your admin,
looking for ``form.label`` in the page is an easy way to catch missing
translations. If you have a recent version of Symfony (2.6) you can also
check the missing translation logger in your tests.

``sonata.admin.label.strategy.form_component``
Not sure why the name, feel free to change this sentence if you know. This
strategy puts everything in lowercase, then capitalizes the first letter.
The above call will produce ``Isvalid``.

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.

0 comments on commit 2af497a

Please sign in to comment.