8000 [TwigBridge] applied previous fix on node visitors · symfony/symfony@f5dd9c7 · GitHub
[go: up one dir, main page]

Skip to content

Commit f5dd9c7

Browse files
committed
[TwigBridge] applied previous fix on node visitors
1 parent 5a2c1c0 commit f5dd9c7

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
class TranslationNodeVisitor implements \Twig_NodeVisitorInterface
2222
{
23+
const UNDEFINED_DOMAIN = '_undefined';
24+
2325
private $enabled = false;
2426
private $messages = array();
2527

@@ -57,7 +59,7 @@ public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
5759
// extract constant nodes with a trans filter
5860
$this->messages[] = array(
5961
$node->getNode('node')->getAttribute('value'),
60-
$node->getNode('arguments')->hasNode(1) ? $node->getNode('arguments')->getNode(1)->getAttribute('value') : null,
62+
$this->readDomain($node->getNode('arguments')->hasNode(1) ? $node->getNode('arguments')->getNode(1) : null),
6163
);
6264
} elseif (
6365
$node instanceof \Twig_Node_Expression_Filter &&
@@ -67,13 +69,13 @@ public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
6769
// extract constant nodes with a trans filter
6870
$this->messages[] = array(
6971
$node->getNode('node')->getAttribute('value'),
70-
$node->getNode('arguments')->hasNode(2) ? $node->getNode('arguments')->getNode(2)->getAttribute('value') : null,
72+
$this->readDomain($node->getNode('arguments')->hasNode(2) ? $node->getNode('arguments')->getNode(2) : null),
7173
);
7274
} elseif ($node instanceof TransNode) {
7375
// extract trans nodes
7476
$this->messages[] = array(
7577
$node->getNode('body')->getAttribute('data'),
76-
null === $node->getNode('domain') ? 'messages' : $node->getNode('domain')->getAttribute('value'),
78+
$this->readDomain($node->getNode('domain')),
7779
);
7880
}
7981

@@ -95,4 +97,17 @@ public function getPriority()
9597
{
9698
return 0;
9799
}
100+
101+
private function readDomain(\Twig_Node $node = null)
102+
{
103+
if (null === $node) {
104+
return null;
105+
}
106+
107+
if ($node instanceof \Twig_Node_Expression_Constant) {
108+
return $node->getAttribute('value');
109+
}
110+
111+
return self::UNDEFINED_DOMAIN;
112+
}
98113
}

src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationNodeVisitorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function getMessagesExtractionTestData()
2626
return array(
2727
array(TwigNodeProvider::getTransFilter($message), array(array($message, null))),
2828
array(TwigNodeProvider::getTransChoiceFilter($message), array(array($message, null))),
29-
array(TwigNodeProvider::getTransTag($message), array(array($message, 'messages'))),
29+
array(TwigNodeProvider::getTransTag($message), array(array($message, null))),
3030
array(TwigNodeProvider::getTransFilter($message, $domain), array(array($message, $domain))),
3131
array(TwigNodeProvider::getTransChoiceFilter($message, $domain), array(array($message, $domain))),
3232
array(TwigNodeProvider::getTransTag($message, $domain), array(array($message, $domain))),

0 commit comments

Comments
 (0)
0