diff --git a/src/Symfony/Component/Translation/Extractor/Visitor/TransMethodVisitor.php b/src/Symfony/Component/Translation/Extractor/Visitor/TransMethodVisitor.php index 53a6981a2681a..011bf3b11219b 100644 --- a/src/Symfony/Component/Translation/Extractor/Visitor/TransMethodVisitor.php +++ b/src/Symfony/Component/Translation/Extractor/Visitor/TransMethodVisitor.php @@ -39,7 +39,7 @@ public function leaveNode(Node $node): ?Node return null; } - $name = (string) $node->name; + $name = $node->name instanceof Node\Name ? $node->name->getLast() : (string) $node->name; if ('trans' === $name || 't' === $name) { $firstNamedArgumentIndex = $this->nodeFirstNamedArgumentIndex($node); diff --git a/src/Symfony/Component/Translation/Tests/Extractor/PhpAstExtractorTest.php b/src/Symfony/Component/Translation/Tests/Extractor/PhpAstExtractorTest.php index 10a144b2c6cd3..9449ca716959b 100644 --- a/src/Symfony/Component/Translation/Tests/Extractor/PhpAstExtractorTest.php +++ b/src/Symfony/Component/Translation/Tests/Extractor/PhpAstExtractorTest.php @@ -82,6 +82,17 @@ public function testExtraction(iterable|string $resource) 'translatable-short '.$expectedNowdoc => 'prefixtranslatable-short '.$expectedNowdoc, 'translatable-short concatenated message with heredoc and nowdoc' => 'prefixtranslatable-short concatenated message with heredoc and nowdoc', 'translatable-short default domain' => 'prefixtranslatable-short default domain', + 'translatable-short-fqn single-quoted key' => 'prefixtranslatable-short-fqn single-quoted key', + 'translatable-short-fqn double-quoted key' => 'prefixtranslatable-short-fqn double-quoted key', + 'translatable-short-fqn heredoc key' => 'prefixtranslatable-short-fqn heredoc key', + 'translatable-short-fqn nowdoc key' => 'prefixtranslatable-short-fqn nowdoc key', + "translatable-short-fqn double-quoted key with whitespace and escaped \$\n\" sequences" => "prefixtranslatable-short-fqn double-quoted key with whitespace and escaped \$\n\" sequences", + 'translatable-short-fqn single-quoted key with whitespace and nonescaped \$\n\' sequences' => 'prefixtranslatable-short-fqn single-quoted key with whitespace and nonescaped \$\n\' sequences', + 'translatable-short-fqn single-quoted key with "quote mark at the end"' => 'prefixtranslatable-short-fqn single-quoted key with "quote mark at the end"', + 'translatable-short-fqn '.$expectedHeredoc => 'prefixtranslatable-short-fqn '.$expectedHeredoc, + 'translatable-short-fqn '.$expectedNowdoc => 'prefixtranslatable-short-fqn '.$expectedNowdoc, + 'translatable-short-fqn concatenated message with heredoc and nowdoc' => 'prefixtranslatable-short-fqn concatenated message with heredoc and nowdoc', + 'translatable-short-fqn default domain' => 'prefixtranslatable-short-fqn default domain', 'single-quoted key' => 'prefixsingle-quoted key', 'double-quoted key' => 'prefixdouble-quoted key', 'heredoc key' => 'prefixheredoc key', @@ -113,6 +124,11 @@ public function testExtraction(iterable|string $resource) 'translatable-short other-domain-test-params-short-array' => 'prefixtranslatable-short other-domain-test-params-short-array', 'translatable-short other-domain-test-params-long-array' => 'prefixtranslatable-short other-domain-test-params-long-array', 'translatable-short typecast' => 'prefixtranslatable-short typecast', + 'translatable-short-fqn other-domain-test-no-params-short-array' => 'prefixtranslatable-short-fqn other-domain-test-no-params-short-array', + 'translatable-short-fqn other-domain-test-no-params-long-array' => 'prefixtranslatable-short-fqn other-domain-test-no-params-long-array', + 'translatable-short-fqn other-domain-test-params-short-array' => 'prefixtranslatable-short-fqn other-domain-test-params-short-array', + 'translatable-short-fqn other-domain-test-params-long-array' => 'prefixtranslatable-short-fqn other-domain-test-params-long-array', + 'translatable-short-fqn typecast' => 'prefixtranslatable-short-fqn typecast', 'other-domain-test-no-params-short-array' => 'prefixother-domain-test-no-params-short-array', 'other-domain-test-no-params-long-array' => 'prefixother-domain-test-no-params-long-array', 'other-domain-test-params-short-array' => 'prefixother-domain-test-params-short-array', @@ -159,6 +175,10 @@ public function testExtraction(iterable|string $resource) $this->assertEquals(['sources' => [$filename.':2']], $catalogue->getMetadata('translatable-short single-quoted key')); $this->assertEquals(['sources' => [$filename.':37']], $catalogue->getMetadata('translatable-short other-domain-test-no-params-short-array', 'not_messages')); + $filename = str_replace(\DIRECTORY_SEPARATOR, '/', __DIR__).'/../Fixtures/extractor-ast/translatable-short-fqn.html.php'; + $this->assertEquals(['sources' => [$filename.':2']], $catalogue->getMetadata('translatable-short-fqn single-quoted key')); + $this->assertEquals(['sources' => [$filename.':37']], $catalogue->getMetadata('translatable-short-fqn other-domain-test-no-params-short-array', 'not_messages')); + $filename = str_replace(\DIRECTORY_SEPARATOR, '/', __DIR__).'/../Fixtures/extractor-ast/translation.html.php'; $this->assertEquals(['sources' => [$filename.':2']], $catalogue->getMetadata('single-quoted key')); $this->assertEquals(['sources' => [$filename.':37']], $catalogue->getMetadata('other-domain-test-no-params-short-array', 'not_messages')); @@ -199,7 +219,7 @@ public static function resourcesProvider(): array if ($fileInfo->isDot()) { continue; } - if (\in_array($fileInfo->getBasename(), ['translatable.html.php', 'translatable-fqn.html.php', 'translatable-short.html.php', 'translation.html.php', 'validator-constraints.php'], true)) { + if (\in_array($fileInfo->getBasename(), ['translatable.html.php', 'translatable-fqn.html.php', 'translatable-short.html.php', 'translatable-short-fqn.html.php', 'translation.html.php', 'validator-constraints.php'], true)) { $phpFiles[] = $fileInfo->getPathname(); } $splFiles[] = $fileInfo->getFileInfo(); diff --git a/src/Symfony/Component/Translation/Tests/Fixtures/extractor-ast/translatable-short-fqn.html.php b/src/Symfony/Component/Translation/Tests/Fixtures/extractor-ast/translatable-short-fqn.html.php new file mode 100644 index 0000000000000..c02e0b51be028 --- /dev/null +++ b/src/Symfony/Component/Translation/Tests/Fixtures/extractor-ast/translatable-short-fqn.html.php @@ -0,0 +1,47 @@ +This template is used for translation message extraction tests + + + + + + + + + + + + + + + + + + 'bar'], 'not_messages'); ?> + + 'bar'], 'not_messages'); ?> + + (int) '123'], 'not_messages'); ?> + + pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy