Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d8b7369

Browse files
committed
WIP
1 parent 63236fa commit d8b7369

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

src/Symfony/Bridge/Twig/Node/TransNode.php

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Bridge\Twig\Node;
1313

14+
use Symfony\Component\Translation\Formatter\TransMessageFormatter;
15+
1416
/**
1517
* @author Fabien Potencier <[email protected]>
1618
*/
@@ -38,30 +40,39 @@ public function compile(\Twig_Compiler $compiler)
3840
}
3941
list($msg, $defaults) = $this->compileString($this->getNode('body'), $defaults, (bool) $vars);
4042

41-
$method = null === $this->getNode('count') ? 'trans' : 'transChoice';
4243

4344
$compiler
44-
->write('echo $this->env->getExtension(\'translator\')->getTranslator()->'.$method.'(')
45+
->write('echo $this->env->getExtension(\'translator\')->getTranslator()->trans(')
4546
->subcompile($msg)
4647
;
4748

4849
$compiler->raw(', ');
4950

50-
if (null !== $this->getNode('count')) {
51-
$compiler
52-
->subcompile($this->getNode('count'))
53-
->raw(', ')
54-
;
55-
}
56-
57-
if (null !== $vars) {
51+
if (null !== $vars || null !== $this->getNode('count')) {
5852
$compiler
5953
->raw('array_merge(')
60-
->subcompile($defaults)
61-
->raw(', ')
62-
->subcompile($this->getNode('vars'))
63-
->raw(')')
64-
;
54+
->subcompile($defaults);
55+
56+
if (null !== $vars) {
57+
$compiler
58+
->raw(', ')
59+
->subcompile($this->getNode('vars'))
60+
;
61+
}
62+
63+
if (null !== $this->getNode('count')) {
64+
$count = new \Twig_Node_Expression_Array(array(
65+
new \Twig_Node_Expression_Constant(TransMessageFormatter::TRANS_CHOICE, 0),
66+
new \Twig_Node_Expression_Constant($this->getNode('count'), 0),
67+
), 0);
68+
69+
$compiler
70+
->raw(', ')
71+
->subcompile($count)
72+
;
73+
}
74+
75+
$compiler->raw(')');
6576
} else {
6677
$compiler->subcompile($defaults);
6778
}

0 commit comments

Comments
 (0)