WordPress.org

Make WordPress Core

Opened 3 weeks ago

Closed 3 weeks ago

#51727 closed defect (bug) (fixed)

REST:API One of the new strings should use _n()

Reported by: tobifjellner Owned by: SergeyBiryukov
Milestone: 5.6 Priority: normal
Severity: normal Version: 5.6
Component: REST API Keywords: has-patch
Focuses: Cc:

Description

New string located in https://build.trac.wordpress.org/browser/trunk/wp-includes/rest-api.php?marks=2090#L2090

%1$s must contain at least %2$s properties.

Since %2$s is a number, this string should enable correct plural handling, using _n()

Attachments (1)

51727.diff (1.5 KB) - added by audrasjb 3 weeks ago.
REST API: replace () with _n()

Download all attachments as: .zip

Change History (7)

@audrasjb
3 weeks ago

REST API: replace () with _n()

#1 @audrasjb
3 weeks ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 5.6

#2 @TimothyBlynJacobs
3 weeks ago

Thanks for catching that @tobifjellner! I think the PHPCS of the patch is incorrect though, @audrasjb.

Last edited 3 weeks ago by TimothyBlynJacobs (previous) (diff)

#3 @SergeyBiryukov
3 weeks ago

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

#4 @SergeyBiryukov
3 weeks ago

Some notes on the patch:

  • Translator comment should be directly above the line with the _n() call, not earlier.
  • _n() should receive the number as is, number_format_i18n() is only needed in the second instance.
  • As noted above, needs some PHPCS corrections.

Looks good otherwise :) This can all be corrected on commit.

#5 @SergeyBiryukov
3 weeks ago

These two strings also need the same adjustment:

if ( isset( $args['minItems'] ) && count( $value ) < $args['minItems'] ) {
	/* translators: 1: Parameter, 2: Number. */
	return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must contain at least %2$s items.' ), $param, number_format_i18n( $args['minItems'] ) ) );
}

if ( isset( $args['maxItems'] ) && count( $value ) > $args['maxItems'] ) {
	/* translators: 1: Parameter, 2: Number. */
	return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must contain at most %2$s items.' ), $param, number_format_i18n( $args['maxItems'] ) ) );
}

#6 @SergeyBiryukov
3 weeks ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 49536:

REST API: Use _n() in some error messages for proper plural forms support.

Follow-up to [47923], [49053].

Props audrasjb, tobifjellner, TimothyBlynJacobs, SergeyBiryukov.
Fixes #51727.

Note: See TracTickets for help on using tickets.