Opened 7 years ago
Last modified 3 years ago
#42140 reviewing defect (bug)
Incorrect use of plural in class-wp-customize-themes-section.php
Reported by: | tobifjellner | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 4.9 |
Component: | Customize | Keywords: | has-patch dev-feedback needs-testing |
Focuses: | javascript | Cc: |
Description
Use of __()
where _n()
is needed.
/wp-includes/customize/class-wp-customize-themes-section.php
/* translators: %s: number of themes displayed. */ echo sprintf( __( '%s themes' ), '<span class="theme-count">0</span>' );
Attachments (4)
Change History (30)
#2
@
7 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
@
7 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
@
7 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.
#5
@
5 years 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!
#7
@
5 years ago
42140.2.diff fixes a couple missing spaces and formatting inconsistencies.
This ticket was mentioned in Slack in #core by whyisjake. View the logs.
4 years ago
#12
@
4 years 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
@
4 years 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?
This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.
4 years ago
This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.
4 years ago
#17
@
4 years ago
- Milestone changed from 5.6 to Future Release
In talking with @dlh, he hasn't had time yet to review. This ticket needs more eyes on it. RC1 is tomorrow. punting this ticket to Future Release
.
If any maintainer or committer feels this can be resolved in time, or wishes to assume ownership during a specific cycle, feel free to update the milestone accordingly.
#18
@
4 years ago
- Milestone changed from Future Release to 5.7
Just noting this would be consistent with the work done for some other scripts in 5.5:
https://core.trac.wordpress.org/query?summary=~wp.i18n&milestone=5.5
The patch looks mostly good at a glance, a few notes though:
- Any strings with placeholders need to keep their translator comments.
- In
wp-includes/customize/class-wp-customize-themes-section.php
, the_n()
usage is incorrect: the third argument should be a number, not a string. - In
js/_enqueues/wp/customize/controls.js
, It looks likecountEl.text()
now receives a%s themes
string instead of just a number, but the associated container still has the same string, so it might be duplicated. This needs some testing.
Let's clean this up a bit in 5.7.
#19
@
4 years ago
You were right, the text string was duplicated.
Would 42140.4 work?
What I am attempting to do is use {{ data.count
}} as the number inside the _n()
,
and move the <span class="theme-count">
so that the complete text string is inside it,
removing the duplication.
This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.
4 years ago
#21
@
4 years ago
- Milestone changed from 5.7 to 5.8
As we are minutes from starting 5.7 RC1 release, ran out of time for this one. Moving to 5.8 which will also allow the fix to run through a full beta cycle.
This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.
4 years ago
This ticket was mentioned in Slack in #core-test by hellofromtonya. View the logs.
3 years ago
#24
@
3 years ago
- Milestone changed from 5.8 to Future Release
Today is 5.8 Beta 1. As there's been no activity and been punted 2x, punting to Future Release
.
#25
@
3 years ago
Can we tag this ticket for 5.9 and simply change these lines into:
/* translators: %s: number of themes displayed. */ echo sprintf( __( 'Number of themes: %s' ), '<span class="theme-count">0</span>' );
@SergeyBiryukov what do you think?
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 say0 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.