Closed
Description
Symfony version(s) affected
all
Description
Currently both
use App\Const\Domain;
$this->translator->trans('foo', Domain::CUSTOM);
in php and
{{ 'foo'|trans({}, constant('App\\Constant\\Domain::CUSTOM')) }};
in twig is misunderstood by translation extractor.
The first one thinks the domain is 'messages'
, the second one '_undefined'
.
It would be nice to correctly support the domain.
If it's really not possible, it seems better to me to have '_undefined'
in both case.
How to reproduce
Running
bin/console debug:translation
with the previous code.
Possible Solution
For the AbstractVisitor, I tried doing something with
if ($node instanceof Node\Expr\ClassConstFetch) {
try {
$reflection = new \ReflectionClass($node->class->toString());
$constant = $reflection->getReflectionConstant($node->name->toString());
if (false !== $constant && \is_string($constant->getValue())) {
return $constant->getValue();
}
} catch (\ReflectionException) {}
}
but this works only with full FQCN, and not when it's imported/aliased at the start of the file...
For twig, I tried #53357
Additional Context
No response