Skip to content

Commit

Permalink
Merge branch '1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveb-p committed Aug 22, 2024
2 parents 90d26b3 + d14af48 commit d5ce930
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
push:
branches:
- "master"
- "1.x"

jobs:
phpunit:
Expand All @@ -33,7 +34,7 @@ jobs:
php-version: '7.4'
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"
with:
fetch-depth: 2

Expand All @@ -51,7 +52,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 }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@

{{ "foo.bar4" | transchoice(5, {'%name%': 'Johannes'}, 'app') }}

{% trans %}text.default_domain{% endtrans %}
{% trans %}text.default_domain{% endtrans %}

{{ "foo.bar5"|trans(domain='app') }}
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
{{ "foo.bar4" | trans({'%count%': 5, '%name%': 'Johannes'}, 'app') }}

{% trans %}text.default_domain{% endtrans %}

{{ "foo.bar5"|trans(domain='app') }}
8 changes: 8 additions & 0 deletions Tests/Translation/Extractor/File/TwigFileExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

Expand Down Expand Up @@ -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'));
}

Expand Down
21 changes: 18 additions & 3 deletions Translation/Extractor/File/TwigFileExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,11 +95,11 @@ public function enterNode(Node $node, Environment $env): Node
}
$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;

Expand Down Expand Up @@ -142,6 +143,20 @@ public function enterNode(Node $node, Environment $env): Node
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;
}

public function getPriority(): int
{
return 0;
Expand Down

0 comments on commit d5ce930

Please sign in to comment.