translate_with_gettext_context

Retrieve the translation of $text in the context defined in $context.

Description

(string) translate_with_gettext_context( (string) $text, (string) $context, (string) $domain = 'default' ); 

If there is no translation, or the text domain isn't loaded the original text is returned.

*Note:* Don't use translate_with_gettext_context() directly, use _x() or related functions.

Returns (string)

Translated text on success, original text on failure.

Parameters (3)

0. $text (string)
Text to translate.
1. $context (string)
Context information for the translators.
2. $domain — Optional. (string) => 'default'
Text domain. Unique identifier for retrieving translated strings. Default default..

Usage

  1. if ( !function_exists( 'translate_with_gettext_context' ) ) { 
  2. require_once ABSPATH . WPINC . '/l10n.php'; 
  3.  
  4. // Text to translate. 
  5. $text = ''; 
  6.  
  7. // Context information for the translators. 
  8. $context = ''; 
  9.  
  10. // Optional. Text domain. Unique identifier for retrieving translated strings. 
  11. // Default 'default'. 
  12. $domain = 'default'; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = translate_with_gettext_context($text, $context, $domain); 
  16.  

Defined (1)

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

/wp-includes/l10n.php  
  1. function translate_with_gettext_context( $text, $context, $domain = 'default' ) { 
  2. $translations = get_translations_for_domain( $domain ); 
  3. $translation = $translations->translate( $text, $context ); 
  4. /** 
  5. * Filters text with its translation based on context information. 
  6. * @since 2.8.0 
  7. * @param string $translation Translated text. 
  8. * @param string $text Text to translate. 
  9. * @param string $context Context information for the translators. 
  10. * @param string $domain Text domain. Unique identifier for retrieving translated strings. 
  11. */ 
  12. return apply_filters( 'gettext_with_context', $translation, $text, $context, $domain );