[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) {
|
foreach ($matches[1] as $var) {
|
||||||
$key = new \Twig_Node_Expression_Constant('%'.$var.'%', $body->getLine());
|
$key = new \Twig_Node_Expression_Constant('%'.$var.'%', $body->getLine());
|
||||||
if (!$vars->hasElement($key)) {
|
if (!$vars->hasElement($key)) {
|
||||||
$varExpr = new \Twig_Node_Expression_Name($var, $body->getLine());
|
if ('count' === $var) {
|
||||||
$varExpr->setAttribute('ignore_strict_check', $ignoreStrictCheck);
|
$vars->addElement($this->getNode('count'), $key);
|
||||||
$vars->addElement($varExpr, $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)),
|
'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 %}',
|
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)),
|
'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
|
// trans filter
|
||||||
array('{{ "Hello"|trans }}', 'Hello'),
|
array('{{ "Hello"|trans }}', 'Hello'),
|
||||||
|
Reference in New Issue
Block a user