8000 [Translation] remove deprecated code paths · symfony/symfony@1a0bfbc · GitHub
[go: up one dir, main page]

Skip to content

Commit 1a0bfbc

Browse files
[Translation] remove deprecated code paths
1 parent 927b1b2 commit 1a0bfbc

File tree

52 files changed

+43
-1879
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+43
-1879
lines changed

src/Symfony/Bridge/Twig/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* removed `TwigEngine` class, use `\Twig\Environment` instead.
8+
* removed `transChoice` filter and token
89

910
4.4.0
1011
-----

src/Symfony/Bridge/Twig/Extension/TranslationExtension.php

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313

1414
use Symfony\Bridge\Twig\NodeVisitor\TranslationDefaultDomainNodeVisitor;
1515
use Symfony\Bridge\Twig\NodeVisitor\TranslationNodeVisitor;
16-
use Symfony\Bridge\Twig\TokenParser\TransChoiceTokenParser;
1716
use Symfony\Bridge\Twig\TokenParser\TransDefaultDomainTokenParser;
1817
use Symfony\Bridge\Twig\TokenParser\TransTokenParser;
19-
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
2018
use Symfony\Contracts\Translation\TranslatorInterface;
2119
use Symfony\Contracts\Translation\TranslatorTrait;
2220
use Twig\Extension\AbstractExtension;
@@ -36,14 +34,8 @@ class TranslationExtension extends AbstractExtension
3634
private $translator;
3735
private $translationNodeVisitor;
3836

39-
/**
40-
* @param TranslatorInterface|null $translator
41-
*/
42-
public function __construct($translator = null, NodeVisitorInterface $translationNodeVisitor = null)
37+
public function __construct(TranslatorInterface $translator = null, NodeVisitorInterface $translationNodeVisitor = null)
4338
{
44-
if (null !== $translator && !$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) {
45-
throw new \TypeError(sprintf('Argument 1 passed to %s() must be an instance of %s, %s given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator)));
46-
}
4739
$this->translator = $translator;
4840
$this->translationNodeVisitor = $translationNodeVisitor;
4941
}
@@ -73,7 +65,6 @@ public function getFilters()
7365
{
7466
return [
7567
new TwigFilter('trans', [$this, 'trans']),
76-
new TwigFilter('transchoice', [$this, 'transchoice'], ['deprecated' => '4.2', 'alternative' => 'trans" with parameter "%count%']),
7768
];
7869
}
7970

@@ -88,11 +79,6 @@ public function getTokenParsers()
8879
// {% trans %}Symfony is great!{% endtrans %}
8980
new TransTokenParser(),
9081

91-
// {% transchoice count %}
92-
// {0} There is no apples|{1} There is one apple|]1,Inf] There is {{ count }} apples
93-
// {% endtranschoice %}
94-
new TransChoiceTokenParser(),
95-
9682
// {% trans_default_domain "foobar" %}
9783
new TransDefaultDomainTokenParser(),
9884
];
@@ -120,20 +106,6 @@ public function trans($message, array $arguments = [], $domain = null, $locale =
120106
return $this->getTranslator()->trans($message, $arguments, $domain, $locale);
121107
}
122108

123-
/**
124-
* @deprecated since Symfony 4.2, use the trans() method instead with a %count% parameter
125-
*/
126-
public function transchoice($message, $count, array $arguments = [], $domain = null, $locale = null)
127-
{
128-
$translator = $this->getTranslator();
129-
130-
if ($translator instanceof TranslatorInterface) {
131-
return $translator->trans($message, array_merge(['%count%' => $count], $arguments), $domain, $locale);
132-
}
133-
134-
return $translator->transChoice($message, $count, array_merge(['%count%' => $count], $arguments), $domain, $locale);
135-
}
136-
137109
/**
138110
* {@inheritdoc}
139111
*/

src/Symfony/Bridge/Twig/Node/TransNode.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ public function compile(Compiler $compiler)
5757
}
5858
list($msg, $defaults) = $this->compileString( F438 $this->getNode('body'), $defaults, (bool) $vars);
5959

60-
$method = !$this->hasNode('count') ? 'trans' : 'transChoice';
61-
6260
$compiler
6361
->write('echo $this->env->getExtension(\'Symfony\Bridge\Twig\Extension\TranslationExtension\')->trans(')
6462
->subcompile($msg)

src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,6 @@ public function testTrans($template, $expected, array $variables = [])
4545
$this->assertEquals($expected, $this->getTemplate($template)->render($variables));
4646
}
4747

48-
/**
49-
* @group legacy
50-
* @dataProvider getTransChoiceTests
51-
*/
52-
public function testTransChoice($template, $expected, array $variables = [])
53-
{
54-
$this->testTrans($template, $expected, $variables);
55-
}
56-
5748
/**
5849
* @expectedException \Twig\Error\SyntaxError
5950
* @expectedExceptionMessage Unexpected token. Twig was looking for the "with", "from", or "into" keyword in "index" at line 3.
@@ -72,16 +63,6 @@ public function testTransComplexBody()
7263
$output = $this->getTemplate("{% trans %}\n{{ 1 + 2 }}{% endtrans %}")->render();
7364
}
7465

75-
/**
76-
* @group legacy
77-
* @expectedException \Twig\Error\SyntaxError
78-
* @expectedExceptionMessage A message inside a transchoice tag must be a simple text in "index" at line 2.
79-
*/
80-
public function testTransChoiceComplexBody()
81-
{
82-
$output = $this->getTemplate("{% transchoice count %}\n{{ 1 + 2 }}{% endtranschoice %}")->render();
83-
}
84-
8566
public function getTransTests()
8667
{
8768
return [
@@ -142,69 +123,6 @@ public function getTransTests()
142123
];
143124
}
144125

145-
/**
146-
* @group legacy
147-
*/
148-
public function getTransChoiceTests()
149-
{
150-
return [
151-
// trans tag
152-
['{% trans %}Hello{% endtrans %}', 'Hello'],
153-
['{% trans %}%name%{% endtrans %}', 'Symfony', ['name' => 'Symfony']],
154-
155-
['{% trans from elsewhere %}Hello{% endtrans %}', 'Hello'],
156-
157-
['{% trans %}Hello %name%{% endtrans %}', 'Hello Symfony', ['name' => 'Symfony']],
158-
['{% trans with { \'%name%\': \'Symfony\' } %}Hello %name%{% endtrans %}', 'Hello Symfony'],
159-
['{% set vars = { \'%name%\': \'Symfony\' } %}{% trans with vars %}Hello %name%{% endtrans %}', 'Hello Symfony'],
160-
161-
['{% trans into "fr"%}Hello{% endtrans %}', 'Hello'],
162-
163-
// transchoice
164-
[
165-
'{% transchoice count from "messages" %}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples{% endtranschoice %}',
166-
'There is no apples',
167-
['count' => 0],
168-
],
169-
[
170-
'{% transchoice count %}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples{% endtranschoice %}',
171-
'There is 5 apples',
172-
['count' => 5],
173-
],
174-
[
175-
'{% transchoice count %}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples (%name%){% endtranschoice %}',
176-
'There is 5 apples (Symfony)',
177-
['count' => 5, 'name' => 'Symfony'],
178-
],
179-
[
180-
'{% transchoice count with { \'%name%\': \'Symfony\' } %}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples (%name%){% endtranschoice %}',
181-
'There is 5 apples (Symfony)',
182-
['count' => 5],
183-
],
184-
[
185-
'{% transchoice count into "fr"%}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples{% endtranschoice %}',
186-
'There is no apples',
187-
['count' => 0],
188-
],
189-
[
190-
'{% transchoice 5 into "fr"%}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples{% endtranschoice %}',
191-
'There is 5 apples',
192-
],
193-
194-
// trans filter
195-
['{{ "Hello"|trans }}', 'Hello'],
196-
['{{ name|trans }}', 'Symfony', ['name' => 'Symfony']],
197-
['{{ hello|trans({ \'%name%\': \'Symfony\' }) }}', 'Hello Symfony', ['hello' => 'Hello %name%']],
198-
['{% set vars = { \'%name%\': \'Symfony\' } %}{{ hello|trans(vars) }}', 'Hello Symfony', ['hello' => 'Hello %name%']],
199-
['{{ "Hello"|trans({}, "messages", "fr") }}', 'Hello'],
200-
201-
// transchoice filter
202-
['{{ "{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples"|transchoice(count) }}', 'There is 5 apples', ['count' => 5]],
203-
['{{ text|transchoice(5, {\'%name%\': \'Symfony\'}) }}', 'There is 5 apples (Symfony)', ['text' => '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples (%name%)']],
204-
['{{ "{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples"|transchoice(count, {}, "messages", "fr") }}', 'There is 5 apples', ['count' => 5]],
205-
];
206-
}
207-
208126
public function testDefaultTranslationDomain()
209127
{
210128
$templates = [

src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,11 @@ public function getDefaultDomainAssignmentTestData()
7979
{
8080
return [
8181
[TwigNodeProvider::getTransFilter(self::$message)],
82-
[TwigNodeProvider::getTransChoiceFilter(self::$message)],
8382
[TwigNodeProvider::getTransTag(self::$message)],
8483
// with named arguments
8584
[TwigNodeProvider::getTransFilter(self::$message, null, [
8685
'arguments' => new ArrayExpression([], 0),
8786
])],
88-
[TwigNodeProvider::getTransChoiceFilter(self::$message), null, [
89-
'arguments' => new ArrayExpression([], 0),
90-
]],
9187
];
9288
}
9389
}

src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationNodeVisitorTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ public function getMessagesExtractionTestData()
5757

5858
return [
5959
[TwigNodeProvider::getTransFilter($message), [[$message, null]]],
60-
[TwigNodeProvider::getTransChoiceFilter($message), [[$message, null]]],
6160
[TwigNodeProvider::getTransTag($message), [[$message, null]]],
6261
[TwigNodeProvider::getTransFilter($message, $domain), [[$message, $domain]]],
63-
[TwigNodeProvider::getTransChoiceFilter($message, $domain), [[$message, $domain]]],
6462
[TwigNodeProvider::getTransTag($message, $domain), [[$message, $domain]]],
6563
];
6664
}

src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,6 @@ public static function getTransFilter($message, $domain = null, $arguments = nul
5353
);
5454
}
5555

56-
public static function getTransChoiceFilter($message, $domain = null, $arguments = null)
57-
{
58-
if (!$arguments) {
59-
$arguments = $domain ? [
60-
new ConstantExpression(0, 0),
61-
new ArrayExpression([], 0),
62-
new ConstantExpression($domain, 0),
63-
] : [];
64-
}
65-
66-
return new FilterExpression(
67-
new ConstantExpression($message, 0),
68-
new ConstantExpression('transchoice', 0),
69-
new Node($arguments),
70-
0
71-
);
72-
}
73-
7456
public static function getTransTag($message, $domain = null)
7557
{
7658
return new TransNode(

src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ public function testExtract($template, $messages)
5050
}
5151
}
5252

53-
/**
54-
* @group legacy
55-
* @dataProvider getLegacyExtractData
56-
*/
57-
public function testLegacyExtract($template, $messages)
58-
{
59-
$this->testExtract($template, $messages);
60-
}
61-
6253
public function getExtractData()
6354
{
6455
return [
@@ -80,24 +71,6 @@ public function getExtractData()
8071
];
8172
}
8273

83-
/**
84-
* @group legacy
85-
*/
86-
public function getLegacyExtractData()
87-
{
88-
return [
89-
['{{ "new key" | transchoice(1) }}', ['new key' => 'messages']],
90-
['{{ "new key" | transchoice(1) | upper }}', ['new key' => 'messages']],
91-
['{{ "new key" | transchoice(1, {}, "domain") }}', ['new key' => 'domain']],
92-
93-
// make sure 'trans_default_domain' tag is supported
94-
['{% trans_default_domain "domain" %}{{ "new key"|transchoice }}', ['new key' => 'domain']],
95-
96-
// make sure this works with twig's named arguments
97-
['{{ "new key" | transchoice(domain="domain", count=1) }}', ['new key' => 'domain']],
98-< 97AE /span>
];
99-
}
100-
10174
/**
10275
* @expectedException \Twig\Error\Error
10376
* @dataProvider resourcesWithSyntaxErrorsProvider

src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php

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

src/Symfony/Bundle/FrameworkBundle/Resources/config/identity_translator.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<defaults public="false" />
88

99
<service id="translator" class="Symfony\Component\Translation\IdentityTranslator" public="true" />
10-
<service id="Symfony\Component\Translation\TranslatorInterface" alias="translator" />
1110
<service id="Symfony\Contracts\Translation\TranslatorInterface" alias="translator" />
1211

1312
<service id="identity_translator" class="Symfony\Component\Translation\IdentityTranslator" />

src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
</call>
2222
<tag name="kernel.locale_aware" />
2323
</service>
24-
<service id="Symfony\Component\Translation\TranslatorInterface" alias="translator" />
2524
<service id="Symfony\Contracts\Translation\TranslatorInterface" alias="translator" />
2625

2726
<service id="translator.logging" class="Symfony\Component\Translation\LoggingTranslator">

0 commit comments

Comments
 (0)
0