#46112 closed defect (bug) (fixed)
Use label_count for requests status view links
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.1 | Priority: | normal |
Severity: | normal | Version: | 5.1 |
Component: | Posts, Post Types | Keywords: | has-patch |
Focuses: | Cc: |
Description
Here's a place in user.php where I don't understand why _n() (actually even _nx() is used.
As long as you only show a number without any surrounding words that would depend on this number, you don't need the hassle of _n().
https://build.trac.wordpress.org/browser/trunk/wp-admin/includes/user.php?marks=1175#L1175
This is a new string for WordPress 5.1
$views[ $status ] = '<a href="' . esc_url( add_query_arg( 'filter-status', $status, $admin_url ) ) . "\" $current_link_attributes>" . sprintf( _nx( '%1$s <span class="count">(%2$d)</span>', '%1$s <span class="count">(%2$d)</span>', $total_status_requests, 'requests' ), esc_html( $label ), number_format_i18n( $total_status_requests ) ) . '</a>';
Attachments (1)
Change History (9)
#1
@
6 years ago
- Summary changed from Administration: Unnecessary use of plural handling in user.php to Administration: Unnecessary use of plural handling for label counts
- Version set to trunk
#2
@
6 years ago
Sentences like
"You have 1 green apple"/"You have 23 green apples" need the _n() construction.
But
"Number of tags: 34" does not.
The point is that words "green apple" will have different form depending on the number. In English it happens to be that there's one form for 1 and another form for all other numbers. But in other langugages, the split may be different. Actually, there's a slight difference already between English and French (if I'm correct) in that English uses plural for 0.
Slavic languages have three different forms, and a few languages, notably Arabic have several.
But: If you use the form "Number of something: xxx", then you don't need _n()
#3
@
6 years ago
- Component changed from General to Posts, Post Types
- Keywords needs-patch added
- Milestone changed from Awaiting Review to 5.1
The use of the plural handling is correct here. What is not correct is that the label gets in added through a placeholder. That's actually the part which needs to be translated based on the count.
#4
@
6 years ago
- Keywords has-patch added; needs-patch removed
- Summary changed from Administration: Unnecessary use of plural handling for label counts to Use label_count for requests status view links
46112.diff uses $post_status->label_count
, fixes the use of %d
in the all view label and makes the core more readable.
#5
@
6 years ago
Thanks @ocean90 that cleans it up greatly and applies cleanly. Looks good in my tests.
I took a look at the origin of the format and it was copied from one of these two places in core;
class-wp-users-list-table.php - https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/class-wp-users-list-table.php#L197
class-wp-ms-users-list-table.php - https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/class-wp-ms-users-list-table.php#L142
*Both instances on $role_links['all']
and missing translators comments.
Should they also be adjusted via this ticket? Or shall I split the above cases into a unique ticket?
Thanks @tobifjellner
This was implemented for #44952 which is in 5.1 and followed some other existing implementations in core.
Example - https://github.com/WordPress/WordPress/blob/f251342de79ae9d42f88dd2084733fcb7914c9c4/wp-admin/includes/class-wp-plugins-list-table.php#L433
If this approach isn't appropriate it should be corrected across core so updated the 'Summary'.