Codex tools: Log in
Retrieve the plural or single form based on the amount.
If the domain is not set in the $l10n list, then a comparison will be made and either $plural or $single parameters returned.
If the domain does exist, then the parameters $single, $plural, and $number will first be passed to the domain's ngettext() method. Then it will be passed to the 'ngettext' filter hook along with the same parameters. The expected type will be a string.
<?php _n( $single, $plural, $number, $domain ) ?>
Display either "1 star" or "x stars" for a star rating plugin.
$rating = '3'; $text = sprintf( _n( '1 star', '%s stars', $rating, 'your_textdomain' ), $rating ); // "3 stars" echo $text;
Important: Never do a calculation inside the
sprintf() function! The following won't work:
$text = sprintf( _n( '1 star', '%s stars', $rating, 'your_textdomain' ), 2 <= $rating ? $rating -1 : $rating );
Example from /wp-admin/edit-comments.php without the use of a text domain for translation.
if ( $approved > 0 ) $messages = sprintf( _n( '%s comment approved', '%s comments approved', $approved ), $approved );
_n() is located in