diff --git a/UPDATE.md b/UPDATE.md index 1d08d5854f25..eef0f78c1815 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -6,8 +6,22 @@ one. It only discusses changes that need to be done when using the "public" API of the framework. If you "hack" the core, you should probably follow the timeline closely anyway. -PR12 to PR13 ------------- +PR12 to beta1 +------------- + +* The `trans` tag does not accept a message as an argument anymore: + + {% trans "foo" %} + {% trans foo %} + + Use the long version the tags or the filter instead: + + {% trans %}foo{% endtrans %} + {{ foo|trans }} + + This has been done to clarify the usage of the tag and filter and also to + make it clearer when the automatic output escaping rules are applied (see + the doc for more information). * Some methods in the DependencyInjection component's ContainerBuilder and Definition classes have been renamed to be more specific and consistent: diff --git a/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php b/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php index 6dc59f821f71..7cc5cc6b7850 100644 --- a/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php @@ -53,7 +53,7 @@ public function getFilters() public function getTokenParsers() { return array( - // {% trans "Symfony is great!" %} + // {% trans %}Symfony is great!{% endtrans %} new TransTokenParser(), // {% transchoice count %} diff --git a/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php index 14e15b403e9e..c3450f67ab5c 100644 --- a/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php +++ b/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php @@ -36,20 +36,14 @@ public function parse(\Twig_Token $token) $vars = new \Twig_Node_Expression_Array(array(), $lineno); $domain = new \Twig_Node_Expression_Constant('messages', $lineno); if (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) { - if (!$stream->test('from') && !$stream->test('with')) { - // {% trans "message" %} - // {% trans message %} - $body = $this->parser->getExpressionParser()->parseExpression(); - } - if ($stream->test('with')) { - // {% trans "message" with vars %} + // {% trans with vars %} $stream->next(); $vars = $this->parser->getExpressionParser()->parseExpression(); } if ($stream->test('from')) { - // {% trans "message" from "messages" %} + // {% trans from "messages" %} $stream->next(); $domain = $this->parser->getExpressionParser()->parseExpression(); } elseif (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) { @@ -57,11 +51,9 @@ public function parse(\Twig_Token $token) } } - if (null === $body) { - // {% trans %}message{% endtrans %} - $stream->expect(\Twig_Token::BLOCK_END_TYPE); - $body = $this->parser->subparse(array($this, 'decideTransFork'), true); - } + // {% trans %}message{% endtrans %} + $stream->expect(\Twig_Token::BLOCK_END_TYPE); + $body = $this->parser->subparse(array($this, 'decideTransFork'), true); if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) { throw new \Twig_Error_Syntax('A message must be a simple text'); diff --git a/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php b/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php index cf21647b2c08..c141336bff58 100644 --- a/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php +++ b/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php @@ -47,16 +47,9 @@ public function getTransTests() { return array( // trans tag - array('{% trans "Hello" %}', 'Hello'), - array('{% trans "Hello %name%" %}', 'Hello Symfony2', array('name' => 'Symfony2')), - array('{% trans name %}', 'Symfony2', array('name' => 'Symfony2')), - array('{% trans hello with { \'%name%\': \'Symfony2\' } %}', 'Hello Symfony2', array('hello' => 'Hello %name%')), - array('{% set vars = { \'%name%\': \'Symfony2\' } %}{% trans hello with vars %}', 'Hello Symfony2', array('hello' => 'Hello %name%')), - array('{% trans %}Hello{% endtrans %}', 'Hello'), array('{% trans %}%name%{% endtrans %}', 'Symfony2', array('name' => 'Symfony2')), - array('{% trans "Hello" from elsewhere %}', 'Hello'), array('{% trans from elsewhere %}Hello{% endtrans %}', 'Hello'), array('{% trans %}Hello %name%{% endtrans %}', 'Hello Symfony2', array('name' => 'Symfony2')),