Ver Fonte

* Add a type and a context to the LabelStrategyInterface
* Convert the breadcrumb to use the LabelStrategyInterface
* Add a BC service so old translation are not broken, to use it add ``label_translator_strategy="sonata.admin.label.strategy.bc"`` when declaring the tag ``name="sonata.admin"``

Thomas Rabaix há 13 anos atrás
pai
commit
b69b8fb1ee
34 ficheiros alterados com 207 adições e 88 exclusões
  1. 6 6
      Admin/Admin.php
  2. 1 1
      Datagrid/ListMapper.php
  3. 15 20
      DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php
  4. 1 1
      Form/FormMapper.php
  5. 1 0
      Resources/config/core.xml
  6. 75 18
      Resources/doc/reference/advance.rst
  7. 13 3
      Resources/doc/reference/translation.rst
  8. 1 1
      Resources/translations/SonataAdminBundle.ca.xliff
  9. 1 1
      Resources/translations/SonataAdminBundle.de.xliff
  10. 1 1
      Resources/translations/SonataAdminBundle.en.xliff
  11. 1 1
      Resources/translations/SonataAdminBundle.es.xliff
  12. 1 1
      Resources/translations/SonataAdminBundle.fr.xliff
  13. 1 1
      Resources/translations/SonataAdminBundle.hr.xliff
  14. 1 1
      Resources/translations/SonataAdminBundle.it.xliff
  15. 1 1
      Resources/translations/SonataAdminBundle.ja.xliff
  16. 1 1
      Resources/translations/SonataAdminBundle.lb.xliff
  17. 1 1
      Resources/translations/SonataAdminBundle.nl.xliff
  18. 1 1
      Resources/translations/SonataAdminBundle.pl.xliff
  19. 1 1
      Resources/translations/SonataAdminBundle.pt_BR.xliff
  20. 1 1
      Resources/translations/SonataAdminBundle.pt_PT.xliff
  21. 1 1
      Resources/translations/SonataAdminBundle.ru.xliff
  22. 1 1
      Resources/translations/SonataAdminBundle.uk.xliff
  23. 4 0
      Show/ShowMapper.php
  24. 26 0
      Tests/Translator/BCLabelTranslatorStrategyTest.php
  25. 2 2
      Tests/Translator/FormLabelTranslatorStrategyTest.php
  26. 4 4
      Tests/Translator/NativeLabelTranslatorStrategyTest.php
  27. 2 2
      Tests/Translator/NoopLabelTranslatorStrategyTest.php
  28. 2 2
      Tests/Translator/UnderscoreLabelTranslatorStrategyTest.php
  29. 27 0
      Translator/BCLabelTranslatorStrategy.php
  30. 2 3
      Translator/FormLabelTranslatorStrategy.php
  31. 4 1
      Translator/LabelTranslatorStrategyInterface.php
  32. 2 3
      Translator/NativeLabelTranslatorStrategy.php
  33. 2 3
      Translator/NoopLabelTranslatorStrategy.php
  34. 3 4
      Translator/UnderscoreLabelTranslatorStrategy.php

+ 6 - 6
Admin/Admin.php

@@ -466,7 +466,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
         $this->uniqid = uniqid();
 
         if (!$this->classnameLabel) {
-            $this->classnameLabel = $this->urlize(substr($this->getClass(), strrpos($this->getClass(), '\\') + 1), '_');
+            $this->classnameLabel = substr($this->getClass(), strrpos($this->getClass(), '\\') + 1);
         }
 
         $this->baseCodeRoute = $this->getCode();
@@ -1710,12 +1710,12 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
         }
 
         $child = $menu->addChild(
-            $this->trans('breadcrumb.dashboard', array(), 'SonataAdminBundle'),
+            $this->trans($this->getLabelTranslatorStrategy()->getLabel('dashboard', 'breadcrumb', 'link'), array(), 'SonataAdminBundle'),
             array('uri' => $this->router->generate('sonata_admin_dashboard'))
         );
 
         $child = $child->addChild(
-            $this->trans(sprintf('breadcrumb.link_%s_list', $this->getClassnameLabel())),
+            $this->trans($this->getLabelTranslatorStrategy()->getLabel(sprintf('%s_list', $this->getClassnameLabel()), 'breadcrumb', 'link')),
             array('uri' => $this->generateUrl('list'))
         );
 
@@ -1734,7 +1734,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
         } elseif ($this->isChild()) {
             if ($action != 'list') {
                 $menu = $menu->addChild(
-                    $this->trans(sprintf('breadcrumb.link_%s_list', $this->getClassnameLabel())),
+                    $this->trans($this->getLabelTranslatorStrategy()->getLabel(sprintf('%s_list', $this->getClassnameLabel()), 'breadcrumb', 'link')),
                     array('uri' => $this->generateUrl('list'))
                 );
             }
@@ -1743,13 +1743,13 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
                 $breadcrumbs = $menu->getBreadcrumbsArray( (string) $this->getSubject());
             } else {
                 $breadcrumbs = $menu->getBreadcrumbsArray(
-                    $this->trans(sprintf('breadcrumb.link_%s_%s', $this->getClassnameLabel(), $action))
+                    $this->trans($this->getLabelTranslatorStrategy()->getLabel(sprintf('%s_%s', $this->getClassnameLabel(), $action), 'breadcrumb', 'link'))
                 );
             }
 
         } else if ($action != 'list') {
             $breadcrumbs = $child->getBreadcrumbsArray(
-                $this->trans(sprintf('breadcrumb.link_%s_%s', $this->getClassnameLabel(), $action))
+                $this->trans($this->getLabelTranslatorStrategy()->getLabel(sprintf('%s_%s', $this->getClassnameLabel(), $action), 'breadcrumb', 'link'))
             );
         } else {
             $breadcrumbs = $child->getBreadcrumbsArray();

+ 1 - 1
Datagrid/ListMapper.php

@@ -66,7 +66,7 @@ class ListMapper
         }
 
         if (!$fieldDescription->getLabel()) {
-            $fieldDescription->setOption('label', $this->admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getName()));
+            $fieldDescription->setOption('label', $this->admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getName(), 'list', 'label'));
         }
 
         // add the field with the FormBuilder

+ 15 - 20
DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php

@@ -32,7 +32,7 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
      */
     public function process(ContainerBuilder $container)
     {
-        $groups = $groupDefaults = $admins = $classes = array();
+        $groupDefaults = $admins = $classes = array();
 
         $pool = $container->getDefinition('sonata.admin.pool');
 
@@ -130,6 +130,7 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
             'validator',
             'security_handler',
             'menu_factory',
+            'route_builder',
             'label_translator_strategy',
         );
 
@@ -163,17 +164,19 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
         $addServices = isset($settings[$serviceId]) ? $settings[$serviceId] : array();
 
         $defaultAddServices = array(
-            'model_manager'      => sprintf('sonata.admin.manager.%s', $manager_type),
-            'form_contractor'    => sprintf('sonata.admin.builder.%s_form', $manager_type),
-            'show_builder'       => sprintf('sonata.admin.builder.%s_show', $manager_type),
-            'list_builder'       => sprintf('sonata.admin.builder.%s_list', $manager_type),
-            'datagrid_builder'   => sprintf('sonata.admin.builder.%s_datagrid', $manager_type),
-            'translator'         => 'translator',
-            'configuration_pool' => 'sonata.admin.pool',
-            'router'             => 'router',
-            'validator'          => 'validator',
-            'security_handler'   => 'sonata.admin.security.handler',
-            'menu_factory'       => 'knp_menu.factory',
+            'model_manager'             => sprintf('sonata.admin.manager.%s', $manager_type),
+            'form_contractor'           => sprintf('sonata.admin.builder.%s_form', $manager_type),
+            'show_builder'              => sprintf('sonata.admin.builder.%s_show', $manager_type),
+            'list_builder'              => sprintf('sonata.admin.builder.%s_list', $manager_type),
+            'datagrid_builder'          => sprintf('sonata.admin.builder.%s_datagrid', $manager_type),
+            'translator'                => 'translator',
+            'configuration_pool'        => 'sonata.admin.pool',
+            'router'                    => 'router',
+            'validator'                 => 'validator',
+            'security_handler'          => 'sonata.admin.security.handler',
+            'menu_factory'              => 'knp_menu.factory',
+            'route_builder'             => 'sonata.admin.route.path_info',
+            'label_translator_strategy' => 'sonata.admin.label.strategy.native'
         );
 
         foreach ($defaultAddServices as $attr => $addServiceId) {
@@ -184,14 +187,6 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
             }
         }
 
-        if (!$definition->hasMethodCall('setRouteBuilder')) {
-            $definition->addMethodCall('setRouteBuilder', array(new Reference('sonata.admin.route.path_info')));
-        }
-
-        if (!$definition->hasMethodCall('setLabelTranslatorStrategy')) {
-            $definition->addMethodCall('setLabelTranslatorStrategy', array(new Reference('sonata.admin.label.strategy.form_component')));
-        }
-
         if (isset($service['label'])) {
             $label = $service['label'];
         } elseif (isset($attributes['label'])) {

+ 1 - 1
Form/FormMapper.php

@@ -104,7 +104,7 @@ class FormMapper
             $options = array_merge($options, $this->formContractor->getDefaultOptions($type, $fieldDescription));
 
             if (!isset($options['label'])) {
-                $options['label'] = $this->admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getName());
+                $options['label'] = $this->admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getName(), 'form', 'label');
             }
 
             $this->formBuilder->add($name, $type, $options);

+ 1 - 0
Resources/config/core.xml

@@ -41,6 +41,7 @@
         </service>
 
         <!-- Services used to format the label, default is sonata.admin.label.strategy.noop -->
+        <service id="sonata.admin.label.strategy.bc" class="Sonata\AdminBundle\Translator\BCLabelTranslatorStrategy" />
         <service id="sonata.admin.label.strategy.native" class="Sonata\AdminBundle\Translator\NativeLabelTranslatorStrategy" />
         <service id="sonata.admin.label.strategy.noop" class="Sonata\AdminBundle\Translator\NoopLabelTranslatorStrategy" />
         <service id="sonata.admin.label.strategy.underscore" class="Sonata\AdminBundle\Translator\UnderscoreLabelTranslatorStrategy" />

+ 75 - 18
Resources/doc/reference/advance.rst

@@ -1,25 +1,76 @@
 Advance
 =======
 
-By default services who are injected to an admin instance are
-
-====================    =============================================
-method name             Service Id
-====================    =============================================
-model_manager           sonata.admin.manager.%manager-type%
-form_contractor         sonata.admin.builder.%manager-type%_form
-show_builder            sonata.admin.builder.%manager-type%_show
-list_builder            sonata.admin.builder.%manager-type%_list
-datagrid_builder        sonata.admin.builder.%manager-type%_datagrid
-translator              translator
-configuration_pool      sonata.admin.pool
-router                  router
-validator               validator
-security_handler        sonata.admin.security.handler
-====================    =============================================
+Service Configuration
+---------------------
+
+When you create a new Admin service you can configure its dependencies, by default services who are injected are:
+
+========================      =============================================
+Dependencies                  Service Id
+========================      =============================================
+model_manager                 sonata.admin.manager.%manager-type%
+form_contractor               sonata.admin.builder.%manager-type%_form
+show_builder                  sonata.admin.builder.%manager-type%_show
+list_builder                  sonata.admin.builder.%manager-type%_list
+datagrid_builder              sonata.admin.builder.%manager-type%_datagrid
+translator                    translator
+configuration_pool            sonata.admin.pool
+router                        router
+validator                     validator
+security_handler              sonata.admin.security.handler
+menu_factory                  knp_menu.factory
+router_builder                sonata.admin.route.path_info
+label_translator_strategy     sonata.admin.label.strategy.form_component
+=========================     =============================================
 
 Note: %manager-type% is replace by the manager type (orm, odm...)
 
+You have 2 ways of defining the dependencies inside a ``services.xml``.
+
+* With a tag attribute, less verbose::
+
+.. code-block:: xml
+
+        <service id="acme.project.admin.security_feed" class="AcmeBundle\ProjectBundle\Admin\ProjectAdmin">
+            <tag
+                name="sonata.admin"
+                manager_type="orm"
+                group="Project"
+                label="Project"
+                label_translator_strategy="sonata.admin.label.strategy.native"
+                router_builder="sonata.admin.route.path_info"
+                />
+            <argument />
+            <argument>AcmeBundle\ProjectBundle\Entity\Project</argument>
+            <argument />
+        </service>
+
+* With a method call, more verbose
+
+.. code-block:: xml
+
+        <service id="acme.project.admin.project" class="AcmeBundle\ProjectBundle\Admin\ProjectAdmin">
+            <tag
+                name="sonata.admin"
+                manager_type="orm"
+                group="Project"
+                label="Project"
+                />
+            <argument />
+            <argument>AcmeBundle\ProjectBundle\Entity\Project</argument>
+            <argument />
+
+            <call method="setLabelTranslatorStrategy">
+                <argument type="service" id="sonata.admin.label.strategy.native" />
+            </call>
+
+            <call method="setRouterBuilder">
+                <argument type="service" id="sonata.admin.route.path_info" />
+            </call>
+        </service>
+
+
 If you want to modify the service who are going to be injected, add the following code to your
 application's config file:
 
@@ -27,6 +78,12 @@ application's config file:
 
     # app/config/config.yml
     admins:
-        sonata_admin: #method name, you can find the list in the table above
-            sonata.order.admin.order: #id of the admin service's
+        sonata_admin:                                           #method name, you can find the list in the table above
+            sonata.order.admin.order:                           #id of the admin service's
                 model_manager: sonata.order.admin.order.manager #id of the your service
+
+
+Admin Extension
+---------------
+
+S

+ 13 - 3
Resources/doc/reference/translation.rst

@@ -76,15 +76,20 @@ By default, the label is the the field name. However a label can be defined as a
 There is another option for rapid prototyping or to avoid spending too much time adding the ``label`` key to all option
 fields: ``Label Strategies``. By default labels are generated by using by using a simple rule ::
 
-    isValid => Isvalid
+    isValid => Is Valid
+
+.. note::
+
+    For early adopter, you can use a specific backward compatible service to keep your current translation.
 
 This is not perfect and hard to read. So in order to solve this, the ``AdminBundle`` comes with different key label generation
 strategies:
 
+* ``sonata.admin.label.strategy.native`` : DEFAULT - Make the string human readable readable - ``isValid`` => ``Is Valid``
 * ``sonata.admin.label.strategy.form_component`` : The default behavior from the Form Component - ``isValid`` => ``Isvalid``)
-* ``sonata.admin.label.strategy.underscore`` : Add undescore to the label  - ``isValid`` => ``label_is_valid``
-* ``sonata.admin.label.strategy.native`` : Make the string human readable readable - ``isValid`` => ``Is Valid``
+* ``sonata.admin.label.strategy.underscore`` : Add undescore to the label  - ``isValid`` => ``form.label_is_valid``
 * ``sonata.admin.label.strategy.noop`` : does not alter the string - ``isValid`` => ``isValid``
+* ``sonata.admin.label.strategy.bc`` : preserve the old label generation from the early version of ``SonataAdminBundle``
 
 ``sonata.admin.label.strategy.underscore`` will be better for i18n applications and ``sonata.admin.label.strategy.native`
 will be better for native language based on the field name. So it is possible to start with the ``native`` strategy and then
@@ -105,3 +110,8 @@ The strategy can be quickly configured when the Admin class is registered into t
 
     In all cases the label will be used by the ``Translator``. The strategy is just a quick way to generate translable keys
     depends on the project's requirements.
+
+
+.. note::
+
+   When the strategy method is called, a context (form, filter, list, show) and a type (link, label, etc ...) arguments are passed.

+ 1 - 1
Resources/translations/SonataAdminBundle.ca.xliff

@@ -155,7 +155,7 @@
               <target>S'ha eliminat correctament l'element.</target>
             </trans-unit>
             <trans-unit id="link_breadcrumb_dashboard">
-                <source>breadcrumb.dashboard</source>
+                <source>breadcrumb.link_dashboard</source>
                 <target>&#8962;</target>
             </trans-unit>
             <trans-unit id="title_delete">

+ 1 - 1
Resources/translations/SonataAdminBundle.de.xliff

@@ -155,7 +155,7 @@
               <target>Element wurde erfolgreich gelöscht.</target>
             </trans-unit>
             <trans-unit id="link_breadcrumb_dashboard">
-                <source>breadcrumb.dashboard</source>
+                <source>breadcrumb.link_dashboard</source>
                 <target>&#8962;</target>
             </trans-unit>
             <trans-unit id="title_delete">

+ 1 - 1
Resources/translations/SonataAdminBundle.en.xliff

@@ -155,7 +155,7 @@
               <target>Item has been deleted successfully.</target>
             </trans-unit>
             <trans-unit id="link_breadcrumb_dashboard">
-                <source>breadcrumb.dashboard</source>
+                <source>breadcrumb.link_dashboard</source>
                 <target>&#8962;</target>
             </trans-unit>
             <trans-unit id="title_delete">

+ 1 - 1
Resources/translations/SonataAdminBundle.es.xliff

@@ -91,7 +91,7 @@
                 <target>expandir/colapsar</target>
             </trans-unit>
             <trans-unit id="link_breadcrumb_dashboard">
-                <source>breadcrumb.dashboard</source>
+                <source>breadcrumb.link_dashboard</source>
                 <target>&#8962;</target>
             </trans-unit>
             <trans-unit id="label_filters">

+ 1 - 1
Resources/translations/SonataAdminBundle.fr.xliff

@@ -155,7 +155,7 @@
               <target>Les éléments ont été supprimés avec succès.</target>
             </trans-unit>
             <trans-unit id="link_breadcrumb_dashboard">
-                <source>breadcrumb.dashboard</source>
+                <source>breadcrumb.link_dashboard</source>
                 <target>&#8962;</target>
             </trans-unit>
             <trans-unit id="title_delete">

+ 1 - 1
Resources/translations/SonataAdminBundle.hr.xliff

@@ -155,7 +155,7 @@
               <target>Element je uspješno izbrisan.</target>
             </trans-unit>
             <trans-unit id="link_breadcrumb_dashboard">
-                <source>breadcrumb.dashboard</source>
+                <source>breadcrumb.link_dashboard</source>
                 <target>&#8962;</target>
             </trans-unit>
             <trans-unit id="title_delete">

+ 1 - 1
Resources/translations/SonataAdminBundle.it.xliff

@@ -151,7 +151,7 @@
                 <target>Elemento eliminato con successo.</target>
             </trans-unit>
             <trans-unit id="link_breadcrumb_dashboard">
-                <source>breadcrumb.dashboard</source>
+                <source>breadcrumb.link_dashboard</source>
                 <target>&#8962;</target>
             </trans-unit>
         </body>

+ 1 - 1
Resources/translations/SonataAdminBundle.ja.xliff

@@ -111,7 +111,7 @@
                 <target>表示</target>
             </trans-unit>
             <trans-unit id="link_breadcrumb_dashboard">
-                <source>breadcrumb.dashboard</source>
+                <source>breadcrumb.link_dashboard</source>
                 <target>&#8962;</target>
             </trans-unit>
         </body>

+ 1 - 1
Resources/translations/SonataAdminBundle.lb.xliff

@@ -155,7 +155,7 @@
               <target>D'Element gouf erfollegräich geläscht.</target>
             </trans-unit>
             <trans-unit id="link_breadcrumb_dashboard">
-                <source>breadcrumb.dashboard</source>
+                <source>breadcrumb.link_dashboard</source>
                 <target>&#8962;</target>
             </trans-unit>
             <trans-unit id="title_delete">

+ 1 - 1
Resources/translations/SonataAdminBundle.nl.xliff

@@ -103,7 +103,7 @@
                 <target>Bekijk</target>
             </trans-unit>
             <trans-unit id="link_breadcrumb_dashboard">
-                <source>breadcrumb.dashboard</source>
+                <source>breadcrumb.link_dashboard</source>
                 <target>&#8962;</target>
             </trans-unit>
         </body>

+ 1 - 1
Resources/translations/SonataAdminBundle.pl.xliff

@@ -155,7 +155,7 @@
               <target>Element został pomyślnie usunięty.</target>
             </trans-unit>
             <trans-unit id="link_breadcrumb_dashboard">
-                <source>breadcrumb.dashboard</source>
+                <source>breadcrumb.link_dashboard</source>
                 <target>&#8962;</target>
             </trans-unit>
             <trans-unit id="title_delete">

+ 1 - 1
Resources/translations/SonataAdminBundle.pt_BR.xliff

@@ -155,7 +155,7 @@
               <target>O item foi apagado com sucesso.</target>
             </trans-unit>
             <trans-unit id="link_breadcrumb_dashboard">
-                <source>breadcrumb.dashboard</source>
+                <source>breadcrumb.link_dashboard</source>
                 <target>&#8962;</target>
             </trans-unit>
 <trans-unit id="title_delete">

+ 1 - 1
Resources/translations/SonataAdminBundle.pt_PT.xliff

@@ -155,7 +155,7 @@
               <target>O item foi apagado com sucesso.</target>
             </trans-unit>
             <trans-unit id="link_breadcrumb_dashboard">
-                <source>breadcrumb.dashboard</source>
+                <source>breadcrumb.link_dashboard</source>
                 <target>Visão Geral</target>
             </trans-unit>
             <trans-unit id="title_delete">

+ 1 - 1
Resources/translations/SonataAdminBundle.ru.xliff

@@ -155,7 +155,7 @@
               <target>Элемент успешно удален.</target>
             </trans-unit>
             <trans-unit id="link_breadcrumb_dashboard">
-                <source>breadcrumb.dashboard</source>
+                <source>breadcrumb.link_dashboard</source>
                 <target>&#8962;</target>
             </trans-unit>
             <trans-unit id="title_delete">

+ 1 - 1
Resources/translations/SonataAdminBundle.uk.xliff

@@ -87,7 +87,7 @@
                 <target>розвернути/звернути</target>
             </trans-unit>
             <trans-unit id="link_breadcrumb_dashboard">
-                <source>breadcrumb.dashboard</source>
+                <source>breadcrumb.link_dashboard</source>
                 <target>&#8962;</target>
             </trans-unit>
         </body>

+ 4 - 0
Show/ShowMapper.php

@@ -73,6 +73,10 @@ class ShowMapper
             throw new \RuntimeException('invalid state');
         }
 
+        if (!$fieldDescription->getLabel()) {
+            $fieldDescription->setOption('label', $this->admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getName(), 'show', 'label'));
+        }
+
         // add the field with the FormBuilder
         $this->showBuilder->addField($this->list, $type, $fieldDescription, $this->admin);
 

+ 26 - 0
Tests/Translator/BCLabelTranslatorStrategyTest.php

@@ -0,0 +1,26 @@
+<?php
+
+/*
+ * This file is part of the Sonata package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+namespace Sonata\AdminBundle\Tests\Translator;
+
+use Sonata\AdminBundle\Translator\BCLabelTranslatorStrategy;
+
+class BCLabelTranslatorStrategyTest extends \PHPUnit_Framework_TestCase
+{
+    public function testLabel()
+    {
+        $strategy = new BCLabelTranslatorStrategy;
+
+        $this->assertEquals('Isvalid', $strategy->getLabel('isValid', 'form', 'label'));
+        $this->assertEquals('Plainpassword', $strategy->getLabel('plainPassword', 'form', 'label'));
+
+        $this->assertEquals('breadcrumb.link_projectversion_list', $strategy->getLabel('ProjectVersion_list', 'breadcrumb', 'link'));
+    }
+}

+ 2 - 2
Tests/Translator/FormLabelTranslatorStrategyTest.php

@@ -18,7 +18,7 @@ class FormLabelTranslatorStrategyTest extends \PHPUnit_Framework_TestCase
     {
         $strategy = new FormLabelTranslatorStrategy;
 
-        $this->assertEquals('Isvalid', $strategy->getLabel('isValid'));
-        $this->assertEquals('Plainpassword', $strategy->getLabel('plainPassword'));
+        $this->assertEquals('Isvalid', $strategy->getLabel('isValid', 'form', 'label'));
+        $this->assertEquals('Plainpassword', $strategy->getLabel('plainPassword', 'form', 'label'));
     }
 }

+ 4 - 4
Tests/Translator/NativeLabelTranslatorStrategyTest.php

@@ -18,9 +18,9 @@ class NativeTranslatorStrategyTest extends \PHPUnit_Framework_TestCase
     {
         $strategy = new NativeLabelTranslatorStrategy;
 
-        $this->assertEquals('Is Valid', $strategy->getLabel('isValid'));
-        $this->assertEquals('Is Valid', $strategy->getLabel('is_Valid'));
-        $this->assertEquals('Is0 Valid', $strategy->getLabel('is0Valid'));
-        $this->assertEquals('Is Valid Super Cool', $strategy->getLabel('isValid_SuperCool'));
+        $this->assertEquals('Is Valid', $strategy->getLabel('isValid', 'form', 'label'));
+        $this->assertEquals('Is Valid', $strategy->getLabel('is_Valid', 'form', 'label'));
+        $this->assertEquals('Is0 Valid', $strategy->getLabel('is0Valid', 'form', 'label'));
+        $this->assertEquals('Is Valid Super Cool', $strategy->getLabel('isValid_SuperCool', 'form', 'label'));
     }
 }

+ 2 - 2
Tests/Translator/NoopLabelTranslatorStrategyTest.php

@@ -18,7 +18,7 @@ class NoopLabelTranslatorStrategyTest extends \PHPUnit_Framework_TestCase
     {
         $strategy = new NoopLabelTranslatorStrategy;
 
-        $this->assertEquals('isValid', $strategy->getLabel('isValid'));
-        $this->assertEquals('isValid_SuperCool', $strategy->getLabel('isValid_SuperCool'));
+        $this->assertEquals('isValid', $strategy->getLabel('isValid', 'form', 'label'));
+        $this->assertEquals('isValid_SuperCool', $strategy->getLabel('isValid_SuperCool', 'form', 'label'));
     }
 }

+ 2 - 2
Tests/Translator/UnderscoreLabelTranslatorStrategyTest.php

@@ -18,7 +18,7 @@ class UnderscoreLabelTranslatorStrategyTest extends \PHPUnit_Framework_TestCase
     {
         $strategy = new UnderscoreLabelTranslatorStrategy;
 
-        $this->assertEquals('label_is_valid', $strategy->getLabel('isValid'));
-        $this->assertEquals('label_is0_valid', $strategy->getLabel('is0Valid'));
+        $this->assertEquals('datagrid.label_is_valid', $strategy->getLabel('isValid', 'datagrid', 'label'));
+        $this->assertEquals('breadcrumb.link_is0_valid', $strategy->getLabel('is0Valid', 'breadcrumb', 'link'));
     }
 }

+ 27 - 0
Translator/BCLabelTranslatorStrategy.php

@@ -0,0 +1,27 @@
+<?php
+
+/*
+ * This file is part of sonata-project.
+ *
+ * (c) 2010 Thomas Rabaix
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sonata\AdminBundle\Translator;
+
+class BCLabelTranslatorStrategy implements LabelTranslatorStrategyInterface
+{
+    /**
+     * {@inheritDoc}
+     */
+    public function getLabel($label, $context = '', $type = '')
+    {
+        if ($context == 'breadcrumb') {
+            return sprintf('%s.%s_%s', $context, $type, strtolower($label));
+        }
+
+        return ucfirst(strtolower($label));
+    }
+}

+ 2 - 3
Translator/FormLabelTranslatorStrategy.php

@@ -14,10 +14,9 @@ namespace Sonata\AdminBundle\Translator;
 class FormLabelTranslatorStrategy implements LabelTranslatorStrategyInterface
 {
     /**
-     * @param string $label
-     * @return string
+     * {@inheritDoc}
      */
-    public function getLabel($label)
+    public function getLabel($label, $context = '', $type = '')
     {
         return ucfirst(strtolower($label));
     }

+ 4 - 1
Translator/LabelTranslatorStrategyInterface.php

@@ -16,6 +16,9 @@ interface LabelTranslatorStrategyInterface
     /**
      * @abstract
      * @param $label
+     * @param $context
+     * @param $type
+     * @return string
      */
-    function getLabel($label);
+    function getLabel($label, $context = '', $type = '');
 }

+ 2 - 3
Translator/NativeLabelTranslatorStrategy.php

@@ -14,10 +14,9 @@ namespace Sonata\AdminBundle\Translator;
 class NativeLabelTranslatorStrategy implements LabelTranslatorStrategyInterface
 {
     /**
-     * @param string $label
-     * @return string
+     * {@inheritDoc}
      */
-    public function getLabel($label)
+    public function getLabel($label, $context = '', $type = '')
     {
         $label = str_replace('_', ' ', $label);
         $label = strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $label));

+ 2 - 3
Translator/NoopLabelTranslatorStrategy.php

@@ -14,10 +14,9 @@ namespace Sonata\AdminBundle\Translator;
 class NoopLabelTranslatorStrategy implements LabelTranslatorStrategyInterface
 {
     /**
-     * @param string $label
-     * @return string
+     * {@inheritDoc}
      */
-    public function getLabel($label)
+    public function getLabel($label, $context = '', $type = '')
     {
         return $label;
     }

+ 3 - 4
Translator/UnderscoreLabelTranslatorStrategy.php

@@ -14,11 +14,10 @@ namespace Sonata\AdminBundle\Translator;
 class UnderscoreLabelTranslatorStrategy implements LabelTranslatorStrategyInterface
 {
     /**
-     * @param string $label
-     * @return string
+     * {@inheritDoc}
      */
-    public function getLabel($label)
+    public function getLabel($label, $context = '', $type = '')
     {
-        return sprintf('label_%s', strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $label)));
+        return sprintf('%s.%s_%s', $context, $type, strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $label)));
     }
 }