[TwigBundle] fixed trans tags
This commit is contained in:
parent
3696066bfe
commit
68bff2d214
@ -18,9 +18,9 @@ namespace Symfony\Bundle\TwigBundle\Node;
|
|||||||
*/
|
*/
|
||||||
class TransNode extends \Twig_Node
|
class TransNode extends \Twig_Node
|
||||||
{
|
{
|
||||||
public function __construct(\Twig_NodeInterface $body, \Twig_NodeInterface $domain, \Twig_Node_Expression $count = null, \Twig_Node_Expression $vars = null, $lineno, $tag = null)
|
public function __construct(\Twig_NodeInterface $body, \Twig_NodeInterface $domain, \Twig_Node_Expression $count = null, \Twig_Node_Expression $vars = null, $isSimple, $lineno, $tag = null)
|
||||||
{
|
{
|
||||||
parent::__construct(array('count' => $count, 'body' => $body, 'domain' => $domain, 'vars' => $vars), array(), $lineno, $tag);
|
parent::__construct(array('count' => $count, 'body' => $body, 'domain' => $domain, 'vars' => $vars), array('is_simple' => $isSimple), $lineno, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,7 +32,7 @@ class TransNode extends \Twig_Node
|
|||||||
{
|
{
|
||||||
$compiler->addDebugInfo($this);
|
$compiler->addDebugInfo($this);
|
||||||
|
|
||||||
if ($this->isSimpleString($this->body)) {
|
if ($this['is_simple']) {
|
||||||
list($msg, $vars) = $this->compileString($this->body);
|
list($msg, $vars) = $this->compileString($this->body);
|
||||||
} else {
|
} else {
|
||||||
$msg = $this->body;
|
$msg = $this->body;
|
||||||
@ -102,21 +102,4 @@ class TransNode extends \Twig_Node
|
|||||||
|
|
||||||
return array(new \Twig_Node(array(new \Twig_Node_Expression_Constant(trim($msg), $node->getLine()))), $vars);
|
return array(new \Twig_Node(array(new \Twig_Node_Expression_Constant(trim($msg), $node->getLine()))), $vars);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function isSimpleString(\Twig_NodeInterface $body)
|
|
||||||
{
|
|
||||||
foreach ($body as $i => $node) {
|
|
||||||
if (
|
|
||||||
$node instanceof \Twig_Node_Text
|
|
||||||
||
|
|
||||||
($node instanceof \Twig_Node_Print && $node->expr instanceof \Twig_Node_Expression_Name)
|
|
||||||
) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ class TransChoiceTokenParser extends TransTokenParser
|
|||||||
|
|
||||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||||
|
|
||||||
return new TransNode($body, $domain, $count, $vars, $lineno, $this->getTag());
|
return new TransNode($body, $domain, $count, $vars, $this->isSimpleString($body), $lineno, $this->getTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function decideTransChoiceFork($token)
|
public function decideTransChoiceFork($token)
|
||||||
|
@ -69,7 +69,7 @@ class TransTokenParser extends \Twig_TokenParser
|
|||||||
|
|
||||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||||
|
|
||||||
return new TransNode($body, $domain, null, $vars, $lineno, $this->getTag());
|
return new TransNode($body, $domain, null, $vars, $this->isSimpleString($body), $lineno, $this->getTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function decideTransFork($token)
|
public function decideTransFork($token)
|
||||||
@ -77,6 +77,27 @@ class TransTokenParser extends \Twig_TokenParser
|
|||||||
return $token->test(array('endtrans'));
|
return $token->test(array('endtrans'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function isSimpleString(\Twig_NodeInterface $body)
|
||||||
|
{
|
||||||
|
if (0 === count($body)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($body as $i => $node) {
|
||||||
|
if (
|
||||||
|
$node instanceof \Twig_Node_Text
|
||||||
|
||
|
||||||
|
($node instanceof \Twig_Node_Print && $node->expr instanceof \Twig_Node_Expression_Name)
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the tag name associated with this token parser.
|
* Gets the tag name associated with this token parser.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user