translate_nooped_plural() WordPress Function

The translate_nooped_plural() function is used to translate a string with a gettext context. This function is similar to the __() function, but with a few key differences. First, the translate_nooped_plural() function allows you to pass in an array of possible plural forms for a string. This is important because gettext context can often be ambiguous, and this function gives you a way to disambiguate the meaning of a string. Second, the translate_nooped_plural() function returns a translated string, instead of a translate() object. This means that you can use the function directly in your code, without having to call the translate() function separately. Lastly, the translate_nooped_plural() function is also available for use in your theme template files. This makes it easy to internationalize your theme, without having to write a lot of code.

translate_nooped_plural( array $nooped_plural, int $count, string $domain = 'default' ) #

Translates and retrieves 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 ) );

Top ↑

Parameters

$nooped_plural

(array)(Required)Array with singular, plural, and context keys, usually the result of _n_noop() or _nx_noop().

$count

(int)(Required)Number of objects.

$domain

(string)(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 value: 'default'


Top ↑

Return

(string) Either $single or $plural translated text.


Top ↑

Source

File: wp-includes/l10n.php

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


Top ↑

Changelog

Changelog
VersionDescription
3.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.