You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #28375 [Translator] Deprecated transChoice and moved it away from contracts (Nyholm, nicolas-grekas)
This PR was merged into the 4.2-dev branch.
Discussion
----------
[Translator] Deprecated transChoice and moved it away from contracts
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | yes
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | Issue: symfony/symfony-docs#10264
This will address comment made here: #27399 (review)
This PR moves the `transChoice()` method away from Contracts and back to the component. I also reverted changes in the `IdentityTranslator`. I will still use the deprecated `MessageSelector` but this is not fine since `transChoice()` is also deprecated.
Commits
-------
dc5f3bf Make trans + %count% parameter resolve plurals
d870a85 [Translator] Deprecated transChoice and moved it away from contracts
thrownew \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)));
array('{{ "{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples"|trans(count=count) }}', 'There is 5 apples', array('count' => 5)),
140
+
array('{{ text|trans(count=5, arguments={\'%name%\': \'Symfony\'}) }}', 'There is 5 apples (Symfony)', array('text' => '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples (%name%)')),
141
+
array('{{ "{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples"|trans({}, "messages", "fr", count) }}', 'There is 5 apples', array('count' => 5)),
142
+
);
143
+
}
144
+
145
+
/**
146
+
* @group legacy
147
+
*/
148
+
publicfunctiongetTransChoiceTests()
149
+
{
150
+
returnarray(
151
+
// trans tag
152
+
array('{% trans %}Hello{% endtrans %}', 'Hello'),
153
+
array('{% trans %}%name%{% endtrans %}', 'Symfony', array('name' => 'Symfony')),
154
+
155
+
array('{% trans from elsewhere %}Hello{% endtrans %}', 'Hello'),
* @deprecated since Symfony 4.2, use the "trans" tag with a "%count%" parameter instead
26
28
*/
27
29
class TransChoiceTokenParser extends TransTokenParser
28
30
{
@@ -38,6 +40,8 @@ public function parse(Token $token)
38
40
$lineno = $token->getLine();
39
41
$stream = $this->parser->getStream();
40
42
43
+
@trigger_error(sprintf('The "transchoice" tag is deprecated since Symfony 4.2, use the "trans" one instead with a "%count%" parameter in %s line %d.', $stream->getSourceContext()->getName(), $lineno), E_USER_DEPRECATED);
0 commit comments