|
@@ -14,7 +14,7 @@ namespace Symfony\Bridge\Twig\TokenParser;
|
|
|
use Symfony\Bridge\Twig\Node\TransNode;
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
+ *
|
|
|
*
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
|
|
*/
|
|
@@ -34,10 +34,17 @@ class TransChoiceTokenParser extends TransTokenParser
|
|
|
|
|
|
$vars = new \Twig_Node_Expression_Array(array(), $lineno);
|
|
|
|
|
|
+ $body = null;
|
|
|
$count = $this->parser->getExpressionParser()->parseExpression();
|
|
|
-
|
|
|
$domain = new \Twig_Node_Expression_Constant('messages', $lineno);
|
|
|
|
|
|
+ if (!$stream->test(\Twig_Token::BLOCK_END_TYPE) && $stream->test('for')) {
|
|
|
+ // {% transchoice count for "message" %}
|
|
|
+ // {% transchoice count for message %}
|
|
|
+ $stream->next();
|
|
|
+ $body = $this->parser->getExpressionParser()->parseExpression();
|
|
|
+ }
|
|
|
+
|
|
|
if ($stream->test('with')) {
|
|
|
// {% transchoice count with vars %}
|
|
|
$stream->next();
|
|
@@ -50,9 +57,11 @@ class TransChoiceTokenParser extends TransTokenParser
|
|
|
$domain = $this->parser->getExpressionParser()->parseExpression();
|
|
|
}
|
|
|
|
|
|
- $stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
|
|
-
|
|
|
- $body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);
|
|
|
+ if (null === $body) {
|
|
|
+ // {% transchoice count %}message{% endtranschoice %}
|
|
|
+ $stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
|
|
+ $body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);
|
|
|
+ }
|
|
|
|
|
|
if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
|
|
|
throw new \Twig_Error_Syntax(sprintf('A message must be a simple text (line %s)', $lineno), -1);
|