8000 bug #42160 [Translation] Extract translatable content on twig set (na… · symfony/symfony@67d8a59 · GitHub
[go: up one dir, main page]

Skip to content

Commit 67d8a59

Browse files
committed
bug #42160 [Translation] Extract translatable content on twig set (natewiebe13)
This PR was submitted for the 5.2 branch but it was squashed and merged into the 5.3 branch instead. Discussion ---------- [Translation] Extract translatable content on twig set | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | License | MIT When extracting messages from Twig templates, the extractor was only considering the `t()` function when it was being immediately filtered by the `trans` filter. Instead it should be happening when the message object is created. Commits ------- ab9ad6b [Translation] Extract translatable content on twig set
2 parents 803a998 + ab9ad6b commit 67d8a59

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,10 @@ protected function doEnterNode(Node $node, Environment $env): Node
6969
$this->getReadDomainFromArguments($node->getNode('arguments'), 1),
7070
];
7171
} elseif (
72-
$node instanceof FilterExpression &&
73-
'trans' === $node->getNode('filter')->getAttribute('value') &&
74-
$node->getNode('node') instanceof FunctionExpression &&
75-
't' === $node->getNode('node')->getAttribute('name')
72+
$node instanceof FunctionExpression &&
73+
't' === $node->getAttribute('name')
7674
) {
77-
$nodeArguments = $node->getNode('node')->getNode('arguments');
75+
$nodeArguments = $node->getNode('arguments');
7876

7977
if ($nodeArguments->getIterator()->current() instanceof ConstantExpression) {
8078
$this->messages[] = [

src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function getExtractData()
6666
['{% set foo = "new key" | trans %}', ['new key' => 'messages']],
6767
['{{ 1 ? "new key" | trans : "another key" | trans }}', ['new key' => 'messages', 'another key' => 'messages']],
6868
['{{ t("new key") | trans() }}', ['new key' => 'messages']],
69+
['{% set foo = t("new key") %}', ['new key' => 'messages']],
6970
['{{ t("new key", {}, "domain") | trans() }}', ['new key' => 'domain']],
7071
['{{ 1 ? t("new key") | trans : t("another key") | trans }}', ['new key' => 'messages', 'another key' => 'messages']],
7172

0 commit comments

Comments
 (0)
0