From 8f7b2cc44d671bd6c00f423645ed3f6b05de3244 Mon Sep 17 00:00:00 2001 From: Abdellatif Ait boudad Date: Thu, 1 May 2014 19:10:47 +0100 Subject: [PATCH] [TwigBridge][Transchoice] set %count% from the current context. --- src/Symfony/Bridge/Twig/Node/TransNode.php | 10 +++++++--- .../Twig/Tests/Extension/TranslationExtensionTest.php | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Node/TransNode.php b/src/Symfony/Bridge/Twig/Node/TransNode.php index 2409090699b7..d459290b6fa4 100644 --- a/src/Symfony/Bridge/Twig/Node/TransNode.php +++ b/src/Symfony/Bridge/Twig/Node/TransNode.php @@ -98,9 +98,13 @@ protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expressio foreach ($matches[1] as $var) { $key = new \Twig_Node_Expression_Constant('%'.$var.'%', $body->getLine()); if (!$vars->hasElement($key)) { - $varExpr = new \Twig_Node_Expression_Name($var, $body->getLine()); - $varExpr->setAttribute('ignore_strict_check', $ignoreStrictCheck); - $vars->addElement($varExpr, $key); + if ('count' === $var) { + $vars->addElement($this->getNode('count'), $key); + } else { + $varExpr = new \Twig_Node_Expression_Name($var, $body->getLine()); + $varExpr->setAttribute('ignore_strict_check', $ignoreStrictCheck); + $vars->addElement($varExpr, $key); + } } } diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php index 524b86bc62e9..11c2d5ad7970 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php @@ -110,6 +110,8 @@ public function getTransTests() 'There is 5 apples (Symfony2)', array('count' => 5)), array('{% transchoice count into "fr"%}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples{% endtranschoice %}', 'There is no apples', array('count' => 0)), + array('{% transchoice 5 into "fr"%}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples{% endtranschoice %}', + 'There is 5 apples'), // trans filter array('{{ "Hello"|trans }}', 'Hello'),