Skip to content

Conversation

@welcoMattic
Copy link
Member

Q A
Branch? 7.4
Bug fix? no
New feature? no
Deprecations? no
Issues Fix #...
License MIT

This PR is the first in a series that tend to improve PhpAstExtractor (covering more extractions cases, ease test writting for new cases, etc).

I've worked with @Jean-Beru, @Kazadri and @jprivet-dev in the past few weeks on various new cases to increase the number of "locations" from where the extractor can extract translation keys.

As we were working on my own Symfony fork, I'm opening the PR.
But to be honest my colleague @Jean-Beru did the large majority of the work here. Thanks to him 👏!

To avoid a big PR containing multiple new small features, we need to open and hopefully merge this one first to ease the tests writting for next new Visitors.


NB: I'm not sure to qualify or not this PR as New feature?

@carsonbot carsonbot added this to the 7.4 milestone Jun 20, 2025
@welcoMattic welcoMattic force-pushed the translation/php-ast-extractor-tests-rework branch 2 times, most recently from 19b3d28 to 2ed841f Compare June 20, 2025 14:11
@@ -0,0 +1,47 @@
This template is used for translation message extraction tests
<?php new TranslatableMessage('translatable single-quoted key'); ?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this missing a use statement ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Also TransMethodVisitor has be updated to check the full classname.

@welcoMattic welcoMattic force-pushed the translation/php-ast-extractor-tests-rework branch from 2ed841f to 23ead95 Compare June 20, 2025 14:38
@OskarStark OskarStark changed the title [Translation] Rework PhpAstExtractor tests organization for future improvements [Translation] Rework PhpAstExtractor tests organization for future improvements Jun 23, 2025
@Jean-Beru Jean-Beru force-pushed the translation/php-ast-extractor-tests-rework branch from 56c8e7c to 9e34c67 Compare August 18, 2025 08:54
$this->assertEquals(['sources' => [self::FIXTURES_FOLDER.'translation.html.php:37']], $catalogue->getMetadata('other-domain-test-no-params-short-array', 'not_messages'));
$this->assertEquals(['sources' => [self::FIXTURES_FOLDER.'translation-73.html.php:8']], $catalogue->getMetadata("nowdoc\nindented\n further"));

$this->assertEquals(['sources' => [self::FIXTURES_FOLDER.'translatable-short.html.php:2']], $catalogue->getMetadata('translatable-short single-quoted key'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This misses the str_replace(\DIRECTORY_SEPARATOR, '/', __DIR__) that was present in the old test (or an equivalent) because the catalogue metadata always stores paths with / as separator instead of the real path.

That's why the CI fails on Windows.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I missed that CI fails on Windows. It's fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants