Title: WP_Translation_Controller::translate
Published: April 3, 2024
Last modified: May 20, 2026

---

# WP_Translation_Controller::translate( string $text, string $context = '', string $textdomain = 'default', string $locale = null ): string|false

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_translation_controller/translate/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_translation_controller/translate/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_translation_controller/translate/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_translation_controller/translate/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_translation_controller/translate/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_translation_controller/translate/?output_format=md#wp--skip-link--target)

Translates a singular string.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_translation_controller/translate/?output_format=md#parameters)󠁿

 `$text`stringrequired

Text to translate.

`$context`stringoptional

Context for the string.

Default:`''`

`$textdomain`stringoptional

Text domain. Default `'default'`.

Default:`'default'`

`$locale`stringoptional

Locale. Default current locale.

Default:`null`

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_translation_controller/translate/?output_format=md#return)󠁿

 string|false Translation on success, false otherwise.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_translation_controller/translate/?output_format=md#source)󠁿

    ```php
    public function translate( string $text, string $context = '', string $textdomain = 'default', ?string $locale = null ) {
    	if ( '' !== $context ) {
    		$context .= "\4";
    	}

    	$translation = $this->locate_translation( "{$context}{$text}", $textdomain, $locale );

    	if ( false === $translation ) {
    		return false;
    	}

    	return $translation['entries'][0];
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/l10n/class-wp-translation-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/l10n/class-wp-translation-controller.php#L263)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/l10n/class-wp-translation-controller.php#L263-L275)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_translation_controller/translate/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Translation_Controller::locate_translation()](https://developer.wordpress.org/reference/classes/wp_translation_controller/locate_translation/)`wp-includes/l10n/class-wp-translation-controller.php` |

Locates translation for a given string and text domain.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_translation_controller/translate/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.5.0](https://developer.wordpress.org/reference/since/6.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_translation_controller%2Ftranslate%2F)
before being able to contribute a note or feedback.