Last active
April 20, 2017 12:25
-
-
Save emodric/77a5f0e16a7c40460ac58e1e6f85354f to your computer and use it in GitHub Desktop.
JMS Translation Bundle Twig 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
... | |
$transchoiceNode = new Node\Transchoice($transchoiceArguments, $transNode->getTemplateLine()); | |
$node->setNode('node', $transchoiceNode); | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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