|
13 | 13 |
|
14 | 14 | use Symfony\Bridge\Twig\Node\TransNode;
|
15 | 15 | use Twig\Environment;
|
| 16 | +use Twig\Node\Expression\Binary\ConcatBinary; |
16 | 17 | use Twig\Node\Expression\ConstantExpression;
|
17 | 18 | use Twig\Node\Expression\FilterExpression;
|
18 | 19 | use Twig\Node\Expression\FunctionExpression;
|
@@ -87,6 +88,16 @@ protected function doEnterNode(Node $node, Environment $env): Node
|
87 | 88 | $node->getNode('body')->getAttribute('data'),
|
88 | 89 | $node->hasNode('domain') ? $this->getReadDomainFromNode($node->getNode('domain')) : null,
|
89 | 90 | ];
|
| 91 | + } elseif ( |
| 92 | + $node instanceof FilterExpression && |
| 93 | + 'trans' === $node->getNode('filter')->getAttribute('value') && |
| 94 | + $node->getNode('node') instanceof ConcatBinary && |
| 95 | + $message = $this->getConcatValueFromNode($node->getNode('node'), null) |
| 96 | + ) { |
| 97 | + $this->messages[] = [ |
| 98 | + $message, |
| 99 | + $this->getReadDomainFromArguments($node->getNode('arguments'), 1), |
| 100 | + ]; |
90 | 101 | }
|
91 | 102 |
|
92 | 103 | return $node;
|
@@ -151,4 +162,28 @@ private function getReadDomainFromNode(Node $node): ?string
|
151 | 162 |
|
152 | 163 | return self::UNDEFINED_DOMAIN;
|
153 | 164 | }
|
| 165 | + |
| 166 | + private function getConcatValueFromNode(Node $node, ?string $value): ?string |
| 167 | + { |
| 168 | + if ($node instanceof ConcatBinary) { |
| 169 | + foreach ($node as $nextNode) { |
| 170 | + if ($nextNode instanceof ConcatBinary) { |
| 171 | + $nextValue = $this->getConcatValueFromNode($nextNode, $value); |
| 172 | + if (null === $nextValue) { |
| 173 | + return null; |
| 174 | + } |
| 175 | + $value .= $nextValue; |
| 176 | + } elseif ($nextNode instanceof ConstantExpression) { |
| 177 | + $value .= $nextNode->getAttribute('value'); |
| 178 | + } else { |
| 179 | + // this is a node we cannot process (variable, or translation in translation) |
| 180 | + return null; |
| 181 | + } |
| 182 | + } |
| 183 | + } elseif ($node instanceof ConstantExpression) { |
| 184 | + $value .= $node->getAttribute('value'); |
| 185 | + } |
| 186 | + |
| 187 | + return $value; |
| 188 | + } |
154 | 189 | }
|
0 commit comments