-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document the label translator strategy feature
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,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. |