chill-bundles/Templating/TranslatableStringTwig.php
Julien Fastré 57f2fa3178 create an helper + twig filter to show translatable string in current locale.
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
2014-11-17 01:03:07 +01:00

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';
}
}