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

In this article

Translates a singular string.

Parameters

$textstringrequired
Text to translate.
$contextstringoptional
Context for the string.

Default:''

$textdomainstringoptional
Text domain. Default 'default'.

Default:'default'

$localestringoptional
Locale. Default current locale.

Default:null

Return

string|false Translation on success, false otherwise.

Source

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];
}

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.