chill-bundles/src/Bundle/ChillMainBundle/Templating/TranslatableStringTwig.php
2021-11-30 13:54:58 +01:00

67 lines
1.4 KiB
PHP

<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Templating;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
class TranslatableStringTwig extends AbstractExtension
{
use ContainerAwareTrait;
/**
* @var TranslatableStringHelper
*/
private $helper;
/**
* TranslatableStringTwig constructor.
*/
public function __construct(TranslatableStringHelper $translatableStringHelper)
{
$this->helper = $translatableStringHelper;
}
/**
* Returns a list of filters to add to the existing list.
*
* (non-PHPdoc)
*
* @see Twig_Extension::getFilters()
*/
public function getFilters()
{
return [
new TwigFilter(
'localize_translatable_string',
[$this, 'localize']
), ];
}
/**
* Returns the name of the extension.
*
* @return The name of the extension.
*/
public function getName()
{
return 'chill_main_localize';
}
public function localize(array $translatableStrings)
{
return $this->helper
->localize($translatableStrings);
}
}