Here’s an example where a string from a certain text domain is translated using the gettext
filter:
/**
* Translate a certain string from a particular text domain.
*
* @param string $translation Translated text.
* @param string $text Text to translate.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
*
* @return string
*/
add_filter( 'gettext', 'wpse_translate_string', 10, 3 );
function wpse_translate_string( $translation, $text, $domain ) {
if ( 'plugin_text_domain' === $domain ) {
if ( 'Original string...' === $text ) {
$translation = 'New string!';
}
}
return $translation;
}