UnderscoreLabelTranslatorStrategy.php 779 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Translator;
  11. /**
  12. * Class UnderscoreLabelTranslatorStrategy.
  13. *
  14. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  15. */
  16. class UnderscoreLabelTranslatorStrategy implements LabelTranslatorStrategyInterface
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function getLabel($label, $context = '', $type = '')
  22. {
  23. $label = str_replace('.', '_', $label);
  24. return sprintf('%s.%s_%s', $context, $type, strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $label)));
  25. }
  26. }