translate

Retrieve the translation of $text.

Description

(string) translate( (string) $text, (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() directly, use __() or related functions.

Returns (string)

Translated text

Parameters (2)

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

Usage

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

Defined (1)

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

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