Skip to content

Commit

Permalink
[TwigBridge] moved the default value for the translation domain to th…
Browse files Browse the repository at this point in the history
…e Node compilation (allows to know when a domain has been provided by the user)
  • Loading branch information
fabpot committed Jan 2, 2012
1 parent c73e034 commit 7424e62
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions src/Symfony/Bridge/Twig/Node/TransNode.php
Expand Up @@ -16,7 +16,7 @@
*/
class TransNode extends \Twig_Node
{
public function __construct(\Twig_NodeInterface $body, \Twig_NodeInterface $domain, \Twig_Node_Expression $count = null, \Twig_Node_Expression $vars = null, \Twig_Node_Expression $locale = null, $lineno = 0, $tag = null)
public function __construct(\Twig_NodeInterface $body, \Twig_NodeInterface $domain = null, \Twig_Node_Expression $count = null, \Twig_Node_Expression $vars = null, \Twig_Node_Expression $locale = null, $lineno = 0, $tag = null)
{
parent::__construct(array('count' => $count, 'body' => $body, 'domain' => $domain, 'vars' => $vars, 'locale' => $locale), array(), $lineno, $tag);
}
Expand Down Expand Up @@ -66,10 +66,14 @@ public function compile(\Twig_Compiler $compiler)
$compiler->subcompile($defaults);
}

$compiler
->raw(', ')
->subcompile($this->getNode('domain'))
;
$compiler->raw(', ');

if (null === $this->getNode('domain')) {
$compiler->repr('messages');
} else {
$compiler->subcompile($this->getNode('domain'));
}

if (null !== $this->getNode('locale')) {
$compiler
->raw(', ')
Expand Down
Expand Up @@ -73,7 +73,7 @@ public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
// extract trans nodes
$this->messages[] = array(
$node->getNode('body')->getAttribute('data'),
$node->getNode('domain')->getAttribute('value'),
null === $node->getNode('domain') ? 'messages' : $node->getNode('domain')->getAttribute('value'),
);
}

Expand Down
Expand Up @@ -36,7 +36,7 @@ public function parse(\Twig_Token $token)

$count = $this->parser->getExpressionParser()->parseExpression();

$domain = new \Twig_Node_Expression_Constant('messages', $lineno);
$domain = null;
$locale = null;

if ($stream->test('with')) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php
Expand Up @@ -33,7 +33,7 @@ public function parse(\Twig_Token $token)
$stream = $this->parser->getStream();

$vars = new \Twig_Node_Expression_Array(array(), $lineno);
$domain = new \Twig_Node_Expression_Constant('messages', $lineno);
$domain = null;
$locale = null;
if (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
if ($stream->test('with')) {
Expand Down

0 comments on commit 7424e62

Please sign in to comment.