Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| publicfunctiontranschoice($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 commitd7eea5a.
| */ | ||
| publicfunctiontransChoice($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;
bocharsky-bwAug 31, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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"
ogizanagiAug 31, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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)
ogizanagi commentedAug 31, 2016
This new behavior can be tested by updating the |
bocharsky-bw commentedAug 31, 2016
Hey@ogizanagi , thanks for your help! |
fabpot commentedSep 14, 2016
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 | noWe 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 fortranschoice Twig filter, but why only for it? It will be consistent to have this for translator in general. We already have a
$numberparameter intransChoice()which we could easily use for that.Before
After: