WP_Translation_Controller::translate
Translates a singular string.
Method of the class: WP_Translation_Controller{}
No Hooks.
Returns
String|false. Translation on success, false otherwise.
Usage
$WP_Translation_Controller = new WP_Translation_Controller(); $WP_Translation_Controller->translate( $text, $context, $textdomain, ?string $locale );
- $text(string) (required)
- Text to translate.
- $context(string)
- Context for the string.
Default:empty string - $textdomain(string)
- Text domain.
Default:'default' - ?string $locale
- .
Default:null
Changelog
| Since 6.5.0 | Introduced. |
WP_Translation_Controller::translate() WP Translation Controller::translate code WP 7.0
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];
}