Translations::translate() WordPress Method
The Translations::translate() Wordpress method is used to translate a string of text from one language to another. This is useful for creating multilingual websites or for providing translations of content for international audiences. The Translations::translate() method accepts two parameters: the string to be translated and the desired language code for the translation. The method will then return the translated string. If you need to translate a string of text on your Wordpress site, then you can use the Translations::translate() method. Simply pass in the string of text to be translated and the desired language code for the translation, and the method will return the translated string.
Translations::translate( string $singular, string $context = null ) #
Parameters
- $singular
(string)(Required)
- $context
(string)(Optional)
Default value: null
Return
(string)
Source
File: wp-includes/pomo/translations.php
public function translate( $singular, $context = null ) {
$entry = new Translation_Entry(
array(
'singular' => $singular,
'context' => $context,
)
);
$translated = $this->translate_entry( $entry );
return ( $translated && ! empty( $translated->translations ) ) ? $translated->translations[0] : $singular;
}
Expand full source codeCollapse full source codeView on TracView on GitHub