wppaste
WordPress

_n( string $single, string $plural, int $number, string $domain = 'default' ): string

Since
2.8.0, 5.5.0
Source
wp-includes/l10n.php:483
Translates and retrieves the singular or plural form based on the supplied number.

Description

Used when you want to use the appropriate form of a string based on whether a number is singular or plural. Example: printf( _n( '%s person', '%s people', $count, 'text-domain' ), number_format_i18n( $count ) );

Parameters

$singlestring
The text to be used if the number is singular.
$pluralstring
The text to be used if the number is plural.
$numberint
The number to compare against to use either the singular or plural form.
$domainstringoptional
Text domain. Unique identifier for retrieving translated strings. Default 'default'.Default: 'default'

Return

string
The translated singular or plural form.

Hooks fired · 2

2 hooks fire while _n() runs, in this order:

  1. apply_filters( ngettext )filterline 498 (+15 into the body)

    Filters the singular or plural form of a string.

  2. apply_filters( ngettext_{$domain} )filterline 513 (+30 into the body)

    Filters the singular or plural form of a string for a domain.

Uses · 2

Used by · 48

Show all 48

Source

function _n( $single, $plural, $number, $domain = 'default' ) {	$translations = get_translations_for_domain( $domain );	$translation  = $translations->translate_plural( $single, $plural, $number ); 	/**	 * Filters the singular or plural form of a string.	 *	 * @since 2.2.0	 *	 * @param string $translation Translated text.	 * @param string $single      The text to be used if the number is singular.	 * @param string $plural      The text to be used if the number is plural.	 * @param int    $number      The number to compare against to use either the singular or plural form.	 * @param string $domain      Text domain. Unique identifier for retrieving translated strings.	 */	$translation = apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain ); 	/**	 * Filters the singular or plural form of a string for a domain.	 *	 * The dynamic portion of the hook name, `$domain`, refers to the text domain.	 *	 * @since 5.5.0	 *	 * @param string $translation Translated text.	 * @param string $single      The text to be used if the number is singular.	 * @param string $plural      The text to be used if the number is plural.	 * @param int    $number      The number to compare against to use either the singular or plural form.	 * @param string $domain      Text domain. Unique identifier for retrieving translated strings.	 */	$translation = apply_filters( "ngettext_{$domain}", $translation, $single, $plural, $number, $domain ); 	return $translation;}

History

Introduced in 5.5.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

5.5.0
Introduced ngettext-{$domain} filter.from the docblock
2.8.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-includes/l10n.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.