_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

  1. if ( !function_exists( '_nx' ) ) { 
  2. require_once ABSPATH . WPINC . '/l10n.php'; 
  3.  
  4. // The text to be used if the number is singular. 
  5. $single = ''; 
  6.  
  7. // The text to be used if the number is plural. 
  8. $plural = ''; 
  9.  
  10. // The number to compare against to use either the singular or plural form. 
  11. $number = null; 
  12.  
  13. // Context information for the translators. 
  14. $context = ''; 
  15.  
  16. // Optional. Text domain. Unique identifier for retrieving translated strings. 
  17. // Default 'default'. 
  18. $domain = 'default'; 
  19.  
  20. // NOTICE! Understand what this does before running. 
  21. $result = _nx($single, $plural, $number, $context, $domain); 
  22.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/l10n.php  
  1. function _nx($single, $plural, $number, $context, $domain = 'default') { 
  2. $translations = get_translations_for_domain( $domain ); 
  3. $translation = $translations->translate_plural( $single, $plural, $number, $context ); 
  4.  
  5. /** 
  6. * Filters the singular or plural form of a string with gettext context. 
  7. * @since 2.8.0 
  8. * @param string $translation Translated text. 
  9. * @param string $single The text to be used if the number is singular. 
  10. * @param string $plural The text to be used if the number is plural. 
  11. * @param string $number The number to compare against to use either the singular or plural form. 
  12. * @param string $context Context information for the translators. 
  13. * @param string $domain Text domain. Unique identifier for retrieving translated strings. 
  14. */ 
  15. return apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain );