WordPress.org

Make WordPress Core

Opened 8 months ago

Closed 8 months ago

Last modified 8 months ago

#46112 closed defect (bug) (fixed)

Use label_count for requests status view links

Reported by: tobifjellner Owned by: ocean90
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)

46112.diff (2.2 KB) - added by ocean90 8 months ago.

Download all attachments as: .zip

Change History (9)

#1 @garrett-eclipse
8 months 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

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

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

@ocean90
8 months ago

#4 @ocean90
8 months 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 @garrett-eclipse
8 months 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?

#6 @ocean90
8 months ago

@garrett-eclipse Thanks for testing! For translator comments we have #44360.

#7 @garrett-eclipse
8 months ago

Thanks @ocean90 I uploaded a patch for one of the missing ones there. As well to keep from muddying the waters of this ticket I created another one (#46122) and uploaded a patch to clean up the two files mentioned. Would love your review.
*Edited w/ proper ticket number

Last edited 8 months ago by garrett-eclipse (previous) (diff)

#8 @ocean90
8 months ago

  • Owner set to ocean90
  • Resolution set to fixed
  • Status changed from new to closed

In 44708:

Privacy: Use label_count property of post status for request counts in the list table views.

See #44952.
Fixes #46112.

Note: See TracTickets for help on using tickets.