Skip to content

Commit 4c7e5de

Browse files
authored
Merge pull request #598 from deguif/remove-legacy-code
Remove legacy code
2 parents 444fa3f + 949414b commit 4c7e5de

24 files changed

+34
-377
lines changed

Resources/doc/usage.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ we use the source message as key:
3333
.. code-block :: jinja
3434
3535
{# index.html.twig #}
36-
{{ "{0} There is no apples|{1} There is one apple|]1,Inf] There are %count% apples"|transchoice(count) }}
36+
{{ "{0} There is no apples|{1} There is one apple|]1,Inf] There are %count% apples"|trans({'%count%': count}) }}
3737
3838
If we translate this to use an abstract key instead, we would get something like
3939
the following:
4040

4141
.. code-block :: jinja
4242
4343
{# index.html.twig #}
44-
{{ "text.apples_remaining"|transchoice(count) }}
44+
{{ "text.apples_remaining"|trans({'%count%': count}) }}
4545
4646
If a translator now sees this abstract key, s/he does not really know what the
4747
expected translation should look like. Fortunately, there is a solution for
@@ -51,7 +51,7 @@ via the ``desc`` filter:
5151
.. code-block :: jinja
5252
5353
{# index.html.twig #}
54-
{{ "text.apples_remaining"|transchoice(count)
54+
{{ "text.apples_remaining"|trans({'%count%': count})
5555
|desc("{0} There is no apples|{1} There is one apple|]1,Inf] There are %count% apples") }}
5656
5757
As you can see we have basically moved the source translation to the ``desc`` filter.
@@ -73,7 +73,7 @@ translations in PHP code, the ``@Desc`` annotation:
7373
7474
// Controller.php
7575
/** @Desc("{0} There is no apples|{1} There is one apple|]1,Inf] There are %count% apples") */
76-
$this->translator->transChoice('text_apples_remaining', $count)
76+
$this->translator->trans('text_apples_remaining', ['%count%' => $count])
7777
7878
You can place the doc comment anywhere in the method call chain or directly
7979
before the key.
@@ -83,11 +83,10 @@ Extracting Translation Messages
8383
This bundle automatically supports extracting messages from the following
8484
sources:
8585

86-
- Twig: ``trans``, and ``transchoice`` filters as well as ``trans``,
87-
and ``transchoice`` blocks
86+
- Twig: ``trans`` filters as well as ``trans`` blocks
8887
- PHP:
8988

90-
- all calls to the ``trans``, or ``transChoice`` method
89+
- all calls to the ``trans`` method
9190
- all classes implementing the ``TranslationContainerInterface``
9291
- all form labels that are defined as options to the ->add() method of the FormBuilder
9392
- messages declared in validation constraints

Tests/Functional/BaseTestCase.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,14 @@ class BaseTestCase extends WebTestCase
2828
{
2929
protected static function createKernel(array $options = []): KernelInterface
3030
{
31-
$isSf5 = version_compare(Kernel::VERSION, '5.0.0') >= 0;
32-
33-
$default = $isSf5 ? 'default_sf5.yml' : 'default.yml';
34-
3531
if (version_compare(Kernel::VERSION, '7.0.0') >= 0) {
3632
$conf = 'framework_sf7.yaml';
3733
} elseif (version_compare(Kernel::VERSION, '6.0.0') >= 0) {
3834
$conf = 'framework_sf6.yml';
39-
} elseif (version_compare(Kernel::VERSION, '5.0.0') >= 0) {
40-
$conf = 'framework.yml';
4135
} else {
4236
$conf = 'framework.yml';
4337
}
4438

45-
return new AppKernel($conf, $options['config'] ?? $default);
39+
return new AppKernel($conf, $options['config'] ?? 'default.yml');
4640
}
4741
}

Tests/Functional/Controller/ApiControllerTest.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace JMS\TranslationBundle\Tests\Functional\Controller;
66

77
use JMS\TranslationBundle\Tests\Functional\BaseTestCase;
8-
use Symfony\Component\HttpKernel\Kernel;
98
use Symfony\Component\Yaml\Yaml;
109

1110
/**
@@ -19,10 +18,8 @@ public function testUpdateAction(): void
1918
$client = static::createClient();
2019
$outputDir = $client->getContainer()->getParameter('translation_output_dir');
2120

22-
$isSf4 = version_compare(Kernel::VERSION, '4.0.0') >= 0;
23-
2421
// Add a file
25-
$file = $isSf4 ? $outputDir . '/navigation.en.yaml' : $outputDir . '/navigation.en.yml';
22+
$file = $outputDir . '/navigation.en.yaml';
2623
$written = file_put_contents($file, 'main.home: Home');
2724
$this->assertTrue($written !== false && $written > 0);
2825

@@ -35,13 +32,7 @@ public function testUpdateAction(): void
3532
// Verify that the file has new content
3633
$array = Yaml::parse($fileContent);
3734

38-
if ($isSf4) {
39-
$this->assertTrue(isset($array['main.home']), print_r($array, true));
40-
$this->assertEquals('Away', $array['main.home']);
41-
} else {
42-
$this->assertTrue(isset($array['main']));
43-
$this->assertTrue(isset($array['main']['home']));
44-
$this->assertEquals('Away', $array['main']['home']);
45-
}
35+
$this->assertTrue(isset($array['main.home']), print_r($array, true));
36+
$this->assertEquals('Away', $array['main.home']);
4637
}
4738
}

Tests/Functional/Fixture/TestBundle/Controller/AppleController.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,4 @@ public function viewAction(): Response
2121
{
2222
return $this->render('@Test/Apple/view.html.twig', ['nbApples' => 5]);
2323
}
24-
25-
#[Route('/view_sf5')]
26-
public function viewsf5Action(): Response
27-
{
28-
return $this->render('@Test/Apple/view_sf5.html.twig', ['nbApples' => 5]);
29-
}
3024
}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
1-
{# This translation does not exist in our messages.en.yml file #}
2-
{{ "text.apples_remaining_does_not_exist"|transchoice(nbApples)
3-
|desc("{0} There is no apple|{1} There is one apple|]1,Inf] There are %count% apples") }}
4-
5-
{# This translation does exist in our messages.en.yml file #}
6-
{{ "text.apples_remaining"|transchoice(nbApples)
1+
{{ "text.apples_remaining"|trans({'%count%': nbApples})
72
|desc("Some default message which should never be applied because it instead is coming from the messages file.") }}

Tests/Functional/Fixture/TestBundle/Resources/views/Apple/view_sf5.html.twig

Lines changed: 0 additions & 2 deletions
This file was deleted.

Tests/Functional/TranslationTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,15 @@
44

55
namespace JMS\TranslationBundle\Tests\Functional;
66

7-
use Symfony\Component\HttpKernel\Kernel;
8-
97
class TranslationTest extends BaseTestCase
108
{
119
public function testTranschoiceWhenTranslationNotYetExtracted(): void
1210
{
13-
$isSf5 = version_compare(Kernel::VERSION, '5.0.0') >= 0;
14-
15-
$url = $isSf5 ? '/apples/view_sf5' : '/apples/view';
1611
$client = $this->createClient();
17-
$client->request('GET', $url);
12+
$client->request('GET', '/apples/view');
1813
$response = $client->getResponse();
1914

2015
$this->assertEquals(200, $response->getStatusCode(), $response->getContent());
21-
$expected = $isSf5 ? "There are 5 apples\n" : "There are 5 apples\n\nThere are 5 apples\n";
22-
$this->assertEquals($expected, $response->getContent());
16+
$this->assertEquals("There are 5 apples\n", $response->getContent());
2317
}
2418
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
imports:
2-
- { resource: framework.yml }
32
- { resource: twig.yml }
43
- { resource: bundle.yml }

Tests/Translation/Extractor/File/Fixture/simple_template.html.twig

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88

99
{% trans with {'%name%': 'Johannes'} from "app" %}text.name{% endtrans %}
1010

11-
{% transchoice count with {'%name%': 'Johannes'} from "app" %}text.apple_choice{% endtranschoice %}
12-
1311
{{ "foo.bar" | trans }}
1412

15-
{{ "foo.bar2" | transchoice(5) }}
13+
{{ "foo.bar2" | trans({'%count%': 5}) }}
1614

1715
{{ "foo.bar3" | trans({'%name%': 'Johannes'}, "app") }}
1816

19-
{{ "foo.bar4" | transchoice(5, {'%name%': 'Johannes'}, 'app') }}
17+
{{ "foo.bar4" | trans({'%count%': 5, '%name%': 'Johannes'}, 'app') }}
2018

21-
{% trans %}text.default_domain{% endtrans %}
19+
{% trans %}text.default_domain{% endtrans %}

Tests/Translation/Extractor/File/Fixture/simple_template_sf5.html.twig

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)