Make WordPress Core

Opened 4 months ago

Last modified 4 months ago

#42140 new defect (bug)

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

Reported by: tobifjellner Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.9
Component: Customize Keywords: needs-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>' );

Change History (4)

#1 @danieltj
4 months 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 4 months ago by danieltj (previous) (diff)

#2 @tobifjellner
4 months 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
4 months 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
4 months 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.

Note: See TracTickets for help on using tickets.