-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Replace %count% with a given number out of the box #19795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -95,7 +95,7 @@ public function trans($message, array $arguments = array(), $domain = null, $loc | |||
|
|||
public function transchoice($message, $count, array $arguments = array(), $domain = null, $locale = null) | |||
{ | |||
return $this->translator->transChoice($message, $count, array_merge(array('%count%' => $count), $arguments), $domain, $locale); | |||
return $this->translator->transChoice($message, $count, $arguments, $domain, $locale); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to keep this in case the twig bridge is used with an older version of the translator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, thanks!
This reverts commit d7eea5a.
@@ -198,6 +198,10 @@ public function trans($id, array $parameters = array(), $domain = null, $locale | |||
*/ | |||
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null) | |||
{ | |||
$parameters = array_merge(array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not?
$parameters['%count%'] = $number;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question! Because of this way we allow devs to override this parameter with their own value. I mean something like this:
print $this->get('translator')
->transChoice('1 apple|%count% apples', 7, [
'%count%' => 'no'
]); // will print "no apples"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about:
$parameters += array('%count%' => $number);
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ogizanagi See this comment: #7029 (comment)
This new behavior can be tested by updating the |
Hey @ogizanagi , thanks for your help! |
Thank you @bocharsky-bw. |
…charsky-bw) This PR was squashed before being merged into the 3.2-dev branch (closes #19795). Discussion ---------- Replace %count% with a given number out of the box | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | no | License | MIT | Doc PR | no We already have this feature for [transchoice](https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php#L98) Twig filter, but why only for it? It will be consistent to have this for translator in general. We already have a `$number` parameter in `transChoice()` which we could easily use for that. Before ```php $this->get('translator') ->transChoice('1 apple|%count% apples', 7, [ '%count%' => 7, ]); ``` After: ```php $this->get('translator') ->transChoice('1 apple|%count% apples', 7); ``` Commits ------- 4c1a65d Replace %count% with a given number out of the box
We already have this feature for transchoice Twig filter, but why only for it? It will be consistent to have this for translator in general. We already have a
$number
parameter intransChoice()
which we could easily use for that.Before
After: