Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
bocharsky-bw wants to merge5 commits intosymfony:masterfrombocharsky-bw:patch-1

Conversation

@bocharsky-bw
Copy link
Contributor

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed ticketsno
LicenseMIT
Doc PRno

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$number parameter intransChoice() which we could easily use for that.

Before

$this->get('translator')    ->transChoice('1 apple|%count% apples',7, ['%count%' =>7,    ]);

After:

$this->get('translator')    ->transChoice('1 apple|%count% apples',7);

linaori, ogizanagi, and javiereguiluz reacted with thumbs up emoji
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);
Copy link
Contributor

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.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You're right, thanks!

*/
publicfunctiontransChoice($id,$number,array$parameters =array(),$domain =null,$locale =null)
{
$parameters =array_merge(array(

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;

Copy link
ContributorAuthor

@bocharsky-bwbocharsky-bwAug 31, 2016
edited
Loading

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"

Copy link
Contributor

@ogizanagiogizanagiAug 31, 2016
edited
Loading

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);

?

Copy link
Contributor

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 reacted with confused emoji
@ogizanagi
Copy link
Contributor

This new behavior can be tested by updating theTranslatorTest::getTransChoiceTests and removing%count% from the given parameters.
Also a new tests case should ensure that the%count% placeholder is overwritable if passed as parameter :)

@bocharsky-bw
Copy link
ContributorAuthor

Hey@ogizanagi , thanks for your help!

@fabpot
Copy link
Member

Thank you@bocharsky-bw.

@fabpotfabpot closed thisSep 14, 2016
fabpot added a commit that referenced this pull requestSep 14, 2016
…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
@bocharsky-bwbocharsky-bw deleted the patch-1 branchSeptember 14, 2016 20:46
@fabpotfabpot mentioned this pull requestOct 27, 2016
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

8 participants

@bocharsky-bw@ogizanagi@fabpot@rybakit@inso@jvasseur@javiereguiluz@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp