[TwigBridge][Transchoice] set %count% from the current context.
This commit is contained in:
parent
d1267cb2d7
commit
8f7b2cc44d
@ -98,11 +98,15 @@ 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)) {
|
||||||
|
if ('count' === $var) {
|
||||||
|
$vars->addElement($this->getNode('count'), $key);
|
||||||
|
} else {
|
||||||
$varExpr = new \Twig_Node_Expression_Name($var, $body->getLine());
|
$varExpr = new \Twig_Node_Expression_Name($var, $body->getLine());
|
||||||
$varExpr->setAttribute('ignore_strict_check', $ignoreStrictCheck);
|
$varExpr->setAttribute('ignore_strict_check', $ignoreStrictCheck);
|
||||||
$vars->addElement($varExpr, $key);
|
$vars->addElement($varExpr, $key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return array(new \Twig_Node_Expression_Constant(str_replace('%%', '%', trim($msg)), $body->getLine()), $vars);
|
return array(new \Twig_Node_Expression_Constant(str_replace('%%', '%', trim($msg)), $body->getLine()), $vars);
|
||||||
}
|
}
|
||||||
|
@ -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