Skip to content

Commit

Permalink
[TwigBridge][Transchoice] set %count% from the current context.
Browse files Browse the repository at this point in the history
  • Loading branch information
aitboudad committed May 1, 2014
1 parent d1267cb commit 8f7b2cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Symfony/Bridge/Twig/Node/TransNode.php
Expand Up @@ -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) {

This comment has been minimized.

Copy link
@kassymbekoff

kassymbekoff May 26, 2014

I had fatal error after this code changed:
{code}
ContextErrorException: Catchable Fatal Error: Argument 1 passed to Twig_Node_Expression_Array::addElement() must be an instance of Twig_Node_Expression, null given, called in /Users/LafaNetwork/projects/et/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Node/TransNode.php on line 102 and defined in /Users/LafaNetwork/projects/et/vendor/twig/twig/lib/Twig/Node/Expression/Array.php line 54
{code}
and when I returned old code, it was worked again

This comment has been minimized.

Copy link
@aitboudad

aitboudad May 26, 2014

Author Contributor

fixed #10995

$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);
}
}
}

Expand Down
Expand Up @@ -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'),
Expand Down

0 comments on commit 8f7b2cc

Please sign in to comment.