translate_nooped_plural( array $nooped_plural, int $count, string $domain = ‘default’ ): string

Translates and returns the singular or plural form of a string that’s been registered with _n_noop() or _nx_noop() .

Description

Used when you want to use a translatable plural string once the number is known.

Example:

$message = _n_noop( '%s post', '%s posts', 'text-domain' );
...
printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) );

Parameters

$nooped_pluralarrayrequired
Array that is usually a return value from _n_noop() or _nx_noop() .
  • singular string
    Singular form to be localized.
  • plural string
    Plural form to be localized.
  • context string|null
    Context information for the translators.
  • domain string|null
    Text domain.
$countintrequired
Number of objects.
$domainstringoptional
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'.
More Arguments from _n_noop( … $domain )Text domain. Unique identifier for retrieving translated strings.

Default:'default'

Return

string Either $singular or $plural translated text.

Source

function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) {
	if ( $nooped_plural['domain'] ) {
		$domain = $nooped_plural['domain'];
	}

	if ( $nooped_plural['context'] ) {
		return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain );
	} else {
		return _n( $nooped_plural['singular'], $nooped_plural['plural'], $count, $domain );
	}
}

Changelog

VersionDescription
3.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.