Make WordPress Core

Opened 3 years ago

Last modified 5 days ago

#42140 reviewing defect (bug)

Incorrect use of plural in class-wp-customize-themes-section.php

Reported by: tobifjellner Owned by: SergeyBiryukov
Milestone: 5.6 Priority: normal
Severity: normal Version: 4.9
Component: Customize Keywords: has-patch dev-feedback needs-testing
Focuses: javascript Cc:


Use of __() where _n() is needed.


/* translators: %s: number of themes displayed. */
echo sprintf( __( '%s themes' ), '<span class="theme-count">0</span>' );

Attachments (3)

42140.diff (9.7 KB) - added by dlh 11 months ago.
42140.2.diff (9.7 KB) - added by dlh 11 months ago.
42140.3.diff (9.9 KB) - added by hellofromTonya 6 days ago.
Refreshes 42140.2.dff to the latest version of wordpress-develop's master branch.

Download all attachments as: .zip

Change History (17)

#1 @danieltj
3 years ago

  • Keywords 2nd-opinion dev-feedback added

I'm not too sure of the issue here, I could be wrong though. After looking at the code in question, the number that is used is hard-coded as 0 (zero).

So irrespective of whether we switch to using _n() or not, when loaded it will always say 0 themes. If this is correct, I'm tempted to change it to _x() instead so we can provide additional context about the 0 in this case.

Last edited 3 years ago by danieltj (previous) (diff)

#2 @tobifjellner
3 years ago

If the number really can be only 0 (zero), then the straightforward solution is to simply use a string with the number 0 explicitly given in the string.
However, if this value can be changed anywhere, then account should be made that many languages have several different plural forms, depending on the specific count.
Alternative approach, less nice, but workable:
Number of themes: followed by the number.

#3 @swissspidy
3 years ago

  • Component changed from Themes to Customize
  • Keywords 2nd-opinion removed

Unfortunately _n() can't be used as these strings are loaded in a JavaScript context, not in PHP. See also #42139.

Although the count is initially 0, it is updated in wp.customize.ThemesSection.updateCount().

We could add a separate string for when there's exactly 1 theme. Then, wp.customize.ThemesSection.updateCount() would switch strings accordingly. Or we really use something like Number of themes: %s or Themes: %s.

As mentioned in the other ticket, this won't be a problem after something like #20491 gets into core.

#4 @celloexpressions
3 years ago

  • Focuses javascript added
  • Keywords needs-patch added; dev-feedback removed
  • Milestone changed from Awaiting Review to Future Release

Yes, this is something that should be addressed once we have a proper set of JS i18n functions in #20491. We don't have a singular workaround there for English because that could still result in issues for other languages. In the meantime, there is an option of leaving it slightly broken or using a colon-type syntax to sidestep the issue.

11 months ago

#5 @dlh
11 months ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Future Release to 5.4

I think this string can now be translated with wp.i18n._n(), as can a handful of other strings in the Customizer JS with singular and plural forms for which various workarounds have been used. 42140.diff contains these updates.

For backcompat, I opted to leave unchanged the affected strings in PHP that have been localized into JS object properties until now. It seemed safe to switch %s theme string originally in question here to use _n(), though, for consistency with the JS translation.

I'm adding this to the 5.4 milestone in the hope that it can be a relatively quick improvement!

#6 @SergeyBiryukov
11 months ago

  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

11 months ago

#7 @dlh
11 months ago

42140.2.diff fixes a couple missing spaces and formatting inconsistencies.

#8 @SergeyBiryukov
8 months ago

  • Milestone changed from 5.4 to 5.5

This ticket was mentioned in Slack in #core by whyisjake. View the logs.

3 months ago

#10 @SergeyBiryukov
3 months ago

  • Milestone changed from 5.5 to 5.6

#11 @whyisjake
3 months ago

Bumping to 5.6 since we are close to closing out the beta.

6 days ago

Refreshes 42140.2.dff to the latest version of wordpress-develop's master branch.

#12 @hellofromTonya
6 days ago

Patch 41240.2.diff did not cleanly apply. Refreshed with 42140.3.diff.

@dlh @SergeyBiryukov Can you double check that all changes are appropriately applied? If yes, what is next for this one to land in 5.6 Beta?

#13 @dlh
5 days ago

Thanks, @hellofromTonya! I'll try to review the latest patch this week.

Other than that, I think the next thing is for a committer to review this ticket and make a decision. If I may take the liberty of pinging @ocean90, who I think has committed a few similar changes recently: Perhaps you'd be able to weigh in on the patch?

#14 @hellofromTonya
5 days ago

  • Keywords dev-feedback needs-testing added
Note: See TracTickets for help on using tickets.