Skip to content

Commit dd33945

Browse files
Merge branch '6.3' into 6.4
* 6.3: [AssetMapper] Handle assets with non-ascii characters in dev server [Translation] Fix `TranslationNodeVisitor` with constant domain [Messenger] [AMQP] Throw exception on `nack` callback [Validator] revise Latvian translations [ErrorHandler] Fix `RecursiveDirectoryIterator` exception with wrong composer autoload [HttpFoundation] Request without content-type or content-length header should result in null values, not empty strings [Cache] Fix possible infinite loop in `CachePoolPass` grab a service from the container only if it exists [Mime] Fix undefined array key 0 when empty sender [Console] Allow '0' as a $shortcut in InputOption.php fix multi-byte code area to convert [Validator] Make it explicit when English translation differs from its resource name
2 parents 5690d4a + a4d5e97 commit dd33945

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

NodeVisitor/TranslationNodeVisitor.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,22 @@ private function getReadDomainFromNode(Node $node): ?string
149149
return $node->getAttribute('value');
150150
}
151151

152+
if (
153+
$node instanceof FunctionExpression
154+
&& 'constant' === $node->getAttribute('name')
155+
) {
156+
$nodeArguments = $node->getNode('arguments');
157+
if ($nodeArguments->getIterator()->current() instanceof ConstantExpression) {
158+
$constantName = $nodeArguments->getIterator()->current()->getAttribute('value');
159+
if (\defined($constantName)) {
160+
$value = \constant($constantName);
161+
if (\is_string($value)) {
162+
return $value;
163+
}
164+
}
165+
}
166+
}
167+
152168
return self::UNDEFINED_DOMAIN;
153169
}
154170

Tests/Translation/TwigExtractorTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
class TwigExtractorTest extends TestCase
2424
{
25+
public const CUSTOM_DOMAIN = 'domain';
26+
2527
/**
2628
* @dataProvider getExtractData
2729
*/
@@ -76,6 +78,11 @@ public static function getExtractData()
7678
// make sure this works with twig's named arguments
7779
['{{ "new key" | trans(domain="domain") }}', ['new key' => 'domain']],
7880

81+
// make sure this works with const domain
82+
['{{ "new key" | trans({}, constant(\'Symfony\\\\Bridge\\\\Twig\\\\Tests\\\\Translation\\\\TwigExtractorTest::CUSTOM_DOMAIN\')) }}', ['new key' => self::CUSTOM_DOMAIN]],
83+
['{% trans from constant(\'Symfony\\\\Bridge\\\\Twig\\\\Tests\\\\Translation\\\\TwigExtractorTest::CUSTOM_DOMAIN\') %}new key{% endtrans %}', ['new key' => self::CUSTOM_DOMAIN]],
84+
['{{ t("new key", {}, constant(\'Symfony\\\\Bridge\\\\Twig\\\\Tests\\\\Translation\\\\TwigExtractorTest::CUSTOM_DOMAIN\')) | trans() }}', ['new key' => self::CUSTOM_DOMAIN]],
85+
7986
// concat translations
8087
['{{ ("new" ~ " key") | trans() }}', ['new key' => 'messages']],
8188
['{{ ("another " ~ "new " ~ "key") | trans() }}', ['another new key' => 'messages']],

0 commit comments

Comments
 (0)