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
This commit is contained in:
John Blackbourn
2022-06-20 22:55:52 +00:00
parent 268015c02d
commit 14a468294f
4 changed files with 24 additions and 15 deletions

View File

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

View File

@@ -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'] ) {

View File

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

View File

@@ -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 ) );