_nx

Advertisement

Summery Summery

Translates and retrieves the singular or plural form based on the supplied number, with gettext context.

Syntax Syntax

_nx( string $single, string $plural, int $number, string $context, string $domain = 'default' )

Description Description

This is a hybrid of _n() and _x(). It supports context and plurals.

Used when you want to use the appropriate form of a string with context based on whether a number is singular or plural.

Example of a generic phrase which is disambiguated via the context parameter:

printf( _nx( '%s group', '%s groups', $people, 'group of people', 'text-domain' ), number_format_i18n( $people ) );
printf( _nx( '%s group', '%s groups', $animals, 'group of animals', 'text-domain' ), number_format_i18n( $animals ) );

Parameters Parameters

$single

(Required) The text to be used if the number is singular.

$plural

(Required) The text to be used if the number is plural.

$number

(Required) The number to compare against to use either the singular or plural form.

$context

(Required) Context information for the translators.

$domain

(Optional) Text domain. Unique identifier for retrieving translated strings. Default 'default'.

Default value: 'default'

Return Return

(string) The translated singular or plural form.

Source Source

File: wp-includes/l10n.php

	 * 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.
	 */
	$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, `$domain`, refers to the text domain.
	 *
	 * @since 5.5.0

Advertisement

Changelog Changelog

Changelog
Version Description
2.8.0 Introduced.

Advertisement

Leave a Reply