Make WordPress Core

Opened 3 years ago

Last modified 13 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
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 (2)

42140.diff (9.7 KB) - added by dlh 8 months ago.
42140.2.diff (9.7 KB) - added by dlh 8 months ago.

Download all attachments as: .zip

Change History (13)

#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.

8 months ago

#5 @dlh
8 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
8 months ago

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

8 months ago

#7 @dlh
8 months ago

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

#8 @SergeyBiryukov
6 months ago

  • Milestone changed from 5.4 to 5.5

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

13 days ago

#10 @SergeyBiryukov
13 days ago

  • Milestone changed from 5.5 to 5.6

#11 @whyisjake
13 days ago

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

Note: See TracTickets for help on using tickets.