Skip to content

Instantly share code, notes, and snippets.

@emodric
Last active April 20, 2017 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emodric/77a5f0e16a7c40460ac58e1e6f85354f to your computer and use it in GitHub Desktop.
Save emodric/77a5f0e16a7c40460ac58e1e6f85354f to your computer and use it in GitHub Desktop.
JMS Translation Bundle Twig 2
<?php
...
$transchoiceNode = new Node\Transchoice($transchoiceArguments, $transNode->getTemplateLine());
$node->setNode('node', $transchoiceNode);
...
namespace JMS\TranslationBundle\Twig\Node;
class Transchoice extends \Twig_Node_Expression
{
public function __construct(\Twig_Node_Expression_Array $arguments, $lineno)
{
parent::__construct(array('arguments' => $arguments), array(), $lineno);
}
public function compile(\Twig_Compiler $compiler)
{
$compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s(', 'JMS\TranslationBundle\Twig\TranslationExtension', 'transchoiceWithDefault'));
$first = true;
foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) {
if (!$first) {
$compiler->raw(', ');
}
$first = false;
$compiler->subcompile($pair['value']);
}
$compiler->raw(')');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment