From 14a468294f10bf8d4ca1aee6551e9b3f02144b77 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Mon, 20 Jun 2022 22:55:52 +0000 Subject: [PATCH] I18N: Correct and improve inline docs and tests for functionality related to nooped plurals. See #55646, #55652 git-svn-id: https://develop.svn.wordpress.org/trunk@53543 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/category-template.php | 2 +- src/wp-includes/l10n.php | 25 ++++++++++++++++--------- src/wp-includes/post.php | 6 ++++-- tests/phpunit/tests/l10n.php | 6 +++--- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/wp-includes/category-template.php b/src/wp-includes/category-template.php index 250c5d378f..326b90771b 100644 --- a/src/wp-includes/category-template.php +++ b/src/wp-includes/category-template.php @@ -823,7 +823,7 @@ function default_topic_count_scale( $count ) { * 'DESC' (descending), or 'RAND' (random). Default 'ASC'. * @type int|bool $filter Whether to enable filtering of the final output * via {@see 'wp_generate_tag_cloud'}. Default 1. - * @type string $topic_count_text Nooped plural text from _n_noop() to supply to + * @type array $topic_count_text Nooped plural text from _n_noop() to supply to * tag counts. Default null. * @type callable $topic_count_text_callback Callback used to generate nooped plural text for * tag counts based on the count. Default null. diff --git a/src/wp-includes/l10n.php b/src/wp-includes/l10n.php index fd817ed067..c68fd8a897 100644 --- a/src/wp-includes/l10n.php +++ b/src/wp-includes/l10n.php @@ -587,12 +587,12 @@ function _nx( $single, $plural, $number, $context, $domain = 'default' ) { * @return array { * Array of translation information for the strings. * - * @type string $0 Singular form to be localized. No longer used. - * @type string $1 Plural form to be localized. No longer used. - * @type string $singular Singular form to be localized. - * @type string $plural Plural form to be localized. - * @type null $context Context information for the translators. - * @type string $domain Text domain. + * @type string $0 Singular form to be localized. No longer used. + * @type string $1 Plural form to be localized. No longer used. + * @type string $singular Singular form to be localized. + * @type string $plural Plural form to be localized. + * @type null $context Context information for the translators. + * @type string|null $domain Text domain. * } */ function _n_noop( $singular, $plural, $domain = null ) { @@ -654,7 +654,7 @@ function _nx_noop( $singular, $plural, $context, $domain = null ) { } /** - * Translates and retrieves the singular or plural form of a string that's been registered + * Translates and returns the singular or plural form of a string that's been registered * with _n_noop() or _nx_noop(). * * Used when you want to use a translatable plural string once the number is known. @@ -667,11 +667,18 @@ function _nx_noop( $singular, $plural, $context, $domain = null ) { * * @since 3.1.0 * - * @param array $nooped_plural Array with singular, plural, and context keys, usually the result of _n_noop() or _nx_noop(). + * @param array $nooped_plural { + * Array that is usually a return value from _n_noop() or _nx_noop(). + * + * @type string $singular Singular form to be localized. + * @type string $plural Plural form to be localized. + * @type string|null $context Context information for the translators. + * @type string|null $domain Text domain. + * } * @param int $count Number of objects. * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. If $nooped_plural contains * a text domain passed to _n_noop() or _nx_noop(), it will override this value. Default 'default'. - * @return string Either $single or $plural translated text. + * @return string Either $singular or $plural translated text. */ function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) { if ( $nooped_plural['domain'] ) { diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 07dd58980e..cbf3e6e59a 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -1254,8 +1254,10 @@ function _wp_privacy_statuses() { * * @type bool|string $label A descriptive name for the post status marked * for translation. Defaults to value of $post_status. - * @type bool|array $label_count Descriptive text to use for nooped plurals. - * Default array of $label, twice. + * @type array|false $label_count Nooped plural text from _n_noop() to provide the singular + * and plural forms of the label for counts. Default false + * which means the `$label` argument will be used for both + * the singular and plural forms of this label. * @type bool $exclude_from_search Whether to exclude posts with this post status * from search results. Default is value of $internal. * @type bool $_builtin Whether the status is built-in. Core-use only. diff --git a/tests/phpunit/tests/l10n.php b/tests/phpunit/tests/l10n.php index b31c165692..e64f232716 100644 --- a/tests/phpunit/tests/l10n.php +++ b/tests/phpunit/tests/l10n.php @@ -22,7 +22,7 @@ class Tests_L10n extends WP_UnitTestCase { $text_domain = 'text-domain'; $nooped_plural = _n_noop( '%s post', '%s posts', $text_domain ); - $this->assertNotEmpty( $nooped_plural['domain'] ); + $this->assertSame( 'text-domain', $nooped_plural['domain'] ); $this->assertSame( '%s posts', translate_nooped_plural( $nooped_plural, 0, $text_domain ) ); $this->assertSame( '%s post', translate_nooped_plural( $nooped_plural, 1, $text_domain ) ); $this->assertSame( '%s posts', translate_nooped_plural( $nooped_plural, 2, $text_domain ) ); @@ -35,8 +35,8 @@ class Tests_L10n extends WP_UnitTestCase { $text_domain = 'text-domain'; $nooped_plural = _nx_noop( '%s post', '%s posts', 'my-context', $text_domain ); - $this->assertNotEmpty( $nooped_plural['domain'] ); - $this->assertNotEmpty( $nooped_plural['context'] ); + $this->assertSame( 'text-domain', $nooped_plural['domain'] ); + $this->assertSame( 'my-context', $nooped_plural['context'] ); $this->assertSame( '%s posts', translate_nooped_plural( $nooped_plural, 0, $text_domain ) ); $this->assertSame( '%s post', translate_nooped_plural( $nooped_plural, 1, $text_domain ) ); $this->assertSame( '%s posts', translate_nooped_plural( $nooped_plural, 2, $text_domain ) );