* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * * @author Fabien Potencier */ class TransExtension extends \Twig_Extension { protected $translator; public function __construct(TranslatorInterface $translator) { $this->translator = $translator; } public function getTranslator() { return $this->translator; } /** * Returns the token parser instance to add to the existing list. * * @return array An array of Twig_TokenParser instances */ public function getTokenParsers() { return array( // {% trans "Symfony is great!" %} new TransTokenParser(), // {% transchoice count %} // {0} There is no apples|{1} There is one apple|]1,Inf] There is {{ count }} apples // {% endtranschoice %} new TransChoiceTokenParser(), ); } /** * Returns the name of the extension. * * @return string The extension name */ public function getName() { return 'translator'; } }