_nx
Translates and retrieves the singular or plural form based on the supplied number, with gettext context.
Description
(string) _nx( (string) $single, (string) $plural, (number) $number, (string) $context, (string) $domain = 'default' );
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:
Returns (string)
The translated singular or plural form.
Parameters (5)
- 0. $single (string)
- The text to be used if the number is singular.
- 1. $plural (string)
- The text to be used if the number is plural.
- 2. $number (number)
- The number to compare against to use either the singular or plural form.
- 3. $context (string)
- Context information for the translators.
- 4. $domain — Optional. (string) =>
'default'
- Text domain. Unique identifier for retrieving translated strings. Default default..
Usage
if ( !function_exists( '_nx' ) ) { require_once ABSPATH . WPINC . '/l10n.php'; } // The text to be used if the number is singular. $single = ''; // The text to be used if the number is plural. $plural = ''; // The number to compare against to use either the singular or plural form. $number = null; // Context information for the translators. $context = ''; // Optional. Text domain. Unique identifier for retrieving translated strings. // Default 'default'. $domain = 'default'; // NOTICE! Understand what this does before running. $result = _nx($single, $plural, $number, $context, $domain);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/l10n.php
- function _nx($single, $plural, $number, $context, $domain = 'default') {
- $translations = get_translations_for_domain( $domain );
- $translation = $translations->translate_plural( $single, $plural, $number, $context );
- /**
- * Filters the singular or plural form of a string with gettext context.
- *
- * @since 2.8.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 $context Context information for the translators.
- * @param string $domain Text domain. Unique identifier for retrieving translated strings.
- */
- return apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain );
- }