[TwigBridge][Transchoice] set %count% from the current context.
This commit is contained in:
parent
d1267cb2d7
commit
8f7b2cc44d
|
@ -98,9 +98,13 @@ class TransNode extends \Twig_Node
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -110,6 +110,8 @@ class TranslationExtensionTest extends TestCase
|
|||
'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'),
|
||||
|
|
Reference in New Issue