Home / APIs / _n() – Translates and retrieves the singular or plural form based on the supplied number.

You appear to be a bot. Output may be restricted

Description

Translates and retrieves the singular or plural form based on the supplied number.

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

Usage

$string = _n( $single, $plural, $number, $domain );

Parameters

$single
( string ) required – The text to be used if the number is singular.
$plural
( string ) required – The text to be used if the number is plural.
$number
( int ) required – The number to compare against to use either the singular or plural form.
$domain
( string ) optional default: default – Optional. Text domain. Unique identifier for retrieving translated strings. Default 'default'.

Returns

string The translated singular or plural form.

Source

File name: wordpress/wp-includes/l10n.php
Lines: 1 to 17 of 17

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 string $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.
 */
  return apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain );
}
 

 View on GitHub View on Trac

Published: 29th June 2017 | Last updated: 4th August 2017

Information

Function name: _n
Plugin ref: WordPress
Version: 5.0.3
Sourcefile: wp-includes/l10n.php
File ref: wp-includes/l10n.php
API type: private
Deprecated?: No
API Letters: _,N

  • Plugins
  • Themes
  • Blocks
  • Shortcodes
  • APIs
  • Files
  • Hooks
  • Classes
  • Sites
  • Sitemap
  • Blog
WP-a2z WordPress core a2z
WordPress core only

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2019. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins