mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
The twig filter is localize_translatable_string Example : {{ person.nationality|localize_translatable_string }} The helper may be called with $container->get('chill.main.helper.translatable_string'). The main function is ->localize(array $strings) Example: $container->get('chill.main.helper.translatable_string')->localize($country->getName()); #return the name in current locale close #299
32 lines
727 B
PHP
32 lines
727 B
PHP
<?php
|
|
namespace Chill\MainBundle\Templating;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
|
|
|
class TranslatableStringTwig extends \Twig_Extension
|
|
{
|
|
use ContainerAwareTrait;
|
|
|
|
/*
|
|
* (non-PHPdoc)
|
|
* @see Twig_Extension::getFilters()
|
|
*/
|
|
public function getFilters()
|
|
{
|
|
return array(
|
|
new \Twig_SimpleFilter('localize_translatable_string', array($this, 'localize'))
|
|
);
|
|
}
|
|
|
|
public function localize(array $translatableStrings)
|
|
{
|
|
return $this->container->get('chill.main.helper.translatable_string')
|
|
->localize($translatableStrings);
|
|
}
|
|
|
|
public function getName()
|
|
{
|
|
return 'chill_main_localize';
|
|
}
|
|
|
|
} |