diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index d5c5bb64..5f8883e9 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -8,6 +8,7 @@ on:
push:
branches:
- "master"
+ - "1.x"
jobs:
phpunit:
@@ -29,7 +30,7 @@ jobs:
- "highest"
steps:
- name: "Checkout"
- uses: "actions/checkout@v2"
+ uses: "actions/checkout@v4"
with:
fetch-depth: 2
@@ -47,7 +48,7 @@ jobs:
args: extra.symfony.require ${{ matrix.symfony-version }}
- name: "Install dependencies with Composer"
- uses: "ramsey/composer-install@v1"
+ uses: "ramsey/composer-install@v3"
with:
dependency-versions: "${{ matrix.dependencies }}"
composer-options: "${{ matrix.composer-options }}"
diff --git a/Tests/Translation/Extractor/File/Fixture/simple_template.html.twig b/Tests/Translation/Extractor/File/Fixture/simple_template.html.twig
index 2d56ebef..f17182bf 100644
--- a/Tests/Translation/Extractor/File/Fixture/simple_template.html.twig
+++ b/Tests/Translation/Extractor/File/Fixture/simple_template.html.twig
@@ -18,4 +18,6 @@
{{ "foo.bar4" | transchoice(5, {'%name%': 'Johannes'}, 'app') }}
-{% trans %}text.default_domain{% endtrans %}
\ No newline at end of file
+{% trans %}text.default_domain{% endtrans %}
+
+{{ "foo.bar5"|trans(domain='app') }}
diff --git a/Tests/Translation/Extractor/File/Fixture/simple_template_sf5.html.twig b/Tests/Translation/Extractor/File/Fixture/simple_template_sf5.html.twig
index 09b09664..0a576dfe 100644
--- a/Tests/Translation/Extractor/File/Fixture/simple_template_sf5.html.twig
+++ b/Tests/Translation/Extractor/File/Fixture/simple_template_sf5.html.twig
@@ -17,3 +17,5 @@
{{ "foo.bar4" | trans({'%count%': 5, '%name%': 'Johannes'}, 'app') }}
{% trans %}text.default_domain{% endtrans %}
+
+{{ "foo.bar5"|trans(domain='app') }}
diff --git a/Tests/Translation/Extractor/File/TwigFileExtractorTest.php b/Tests/Translation/Extractor/File/TwigFileExtractorTest.php
index 3818baa6..9299d230 100644
--- a/Tests/Translation/Extractor/File/TwigFileExtractorTest.php
+++ b/Tests/Translation/Extractor/File/TwigFileExtractorTest.php
@@ -99,6 +99,10 @@ public function testExtractSimpleTemplateInSF5()
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 19));
$expected->add($message);
+ $message = new Message('foo.bar5', 'app');
+ $message->addSource($fileSourceFactory->create($fixtureSplInfo, 21));
+ $expected->add($message);
+
$this->assertEquals($expected, $this->extract('simple_template_sf5.html.twig'));
}
@@ -162,6 +166,10 @@ public function testExtractSimpleTemplate()
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 21));
$expected->add($message);
+ $message = new Message('foo.bar5', 'app');
+ $message->addSource($fileSourceFactory->create($fixtureSplInfo, 23));
+ $expected->add($message);
+
$this->assertEquals($expected, $this->extract('simple_template.html.twig'));
}
diff --git a/Translation/Extractor/File/TwigFileExtractor.php b/Translation/Extractor/File/TwigFileExtractor.php
index 7f21c8b7..1bff8f55 100644
--- a/Translation/Extractor/File/TwigFileExtractor.php
+++ b/Translation/Extractor/File/TwigFileExtractor.php
@@ -27,6 +27,7 @@
use JMS\TranslationBundle\Translation\FileSourceFactory;
use Symfony\Bridge\Twig\Node\TransNode;
use Twig\Environment;
+use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\FilterExpression;
use Twig\Node\Node;
@@ -97,11 +98,11 @@ protected function doEnterNode(Node $node, Environment $env)
}
$id = $idNode->getAttribute('value');
- $index = $name === 'trans' ? 1 : 2;
$domain = 'messages';
$arguments = iterator_to_array($node->getNode('arguments'));
- if (isset($arguments[$index])) {
- $argument = $arguments[$index];
+
+ $argument = $this->findDomainArgument($arguments, $name);
+ if (null !== $argument) {
if (! $argument instanceof ConstantExpression) {
return $node;
@@ -145,6 +146,20 @@ protected function doEnterNode(Node $node, Environment $env)
return $node;
}
+ private function findDomainArgument(array $arguments, string $name): ?AbstractExpression
+ {
+ if (isset($arguments['domain'])) {
+ return $arguments['domain'];
+ }
+
+ $index = $name === 'trans' ? 1 : 2;
+ if (isset($arguments[$index])) {
+ return $arguments[$index];
+ }
+
+ return null;
+ }
+
/**
* @return int
*/
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 712c2c61..6f339c6b 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -17,6 +17,11 @@
+
+
+
+
+
./