10000 fix(translation): Improve performance of debug and extract command fo… · vtsykun/symfony@ae6c25b · GitHub
[go: up one dir, main page]

Skip to content

Commit ae6c25b

Browse files
committed
fix(translation): Improve performance of debug and extract command for big code base
1 parent aadd302 commit ae6c25b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Symfony/Component/Translation/Extractor/PhpAstExtractor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ public function setPrefix(string $prefix): void
6464

6565
protected function canBeExtracted(string $file): bool
6666
{
67-
return 'php' === pathinfo($file, \PATHINFO_EXTENSION) && $this->isFile($file);
67+
return 'php' === pathinfo($file, \PATHINFO_EXTENSION)
68+
&& $this->isFile($file)
69+
&& preg_match('/\bt\(|->trans\(|TranslatableMessage|Symfony\\\\Component\\\\Validator\\\\Constraints/i', file_get_contents($file));
6870
}
6971

7072
protected function extractFromDirectory(array|string $resource): iterable|Finder

src/Symfony/Component/Translation/Extractor/Visitor/ConstraintVisitor.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
*/
2222
final class ConstraintVisitor extends AbstractVisitor implements NodeVisitor
2323
{
24-
private const CONSTRAINT_VALIDATION_MESSAGE_PATTERN = '/[a-zA-Z]*message/i';
25-
2624
public function __construct(
2725
private readonly array $constraintClassNames = []
2826
) {
@@ -65,7 +63,7 @@ public function enterNode(Node $node): ?Node
6563
}
6664

6765
if ($this->hasNodeNamedArguments($node)) {
68-
$messages = $this->getStringArguments($node, self::CONSTRAINT_VALIDATION_MESSAGE_PATTERN, true);
66+
$messages = $this->getStringArguments($node, '/message/i', true);
6967
} else {
7068
if (!$arg->value instanceof Node\Expr\Array_) {
7169
// There is no way to guess which argument is a message to be translated.
@@ -81,7 +79,7 @@ public function enterNode(Node $node): ?Node
8179
continue;
8280
}
8381

84-
if (!preg_match(self::CONSTRAINT_VALIDATION_MESSAGE_PATTERN, $item->key->value ?? '')) {
82+
if (false === stripos($item->key->value ?? '', 'message')) {
8583
continue;
8684
}
8785

0 commit comments

Comments
 (0)
0