How to translate email sending by plugin WP Mail SMTP

On this example we use a filter to translate our email message based on this doc : https://wpmailsmtp.com/docs/setting-a-custom-reply-to-email/

function wp_mail_smtp_weglot( $args ) {
	$original_lang = weglot_get_original_language();
	$current_language = weglot_get_current_language();
	if ( $original_lang == $current_language ) {
		return $args;
	}

	if ( ! empty( $args['message'] ) ) {
		$translate_service = weglot_get_service( 'Pdf_Translate_Service_Weglot' );
		$translate_message = $translate_service->translate_pdf( $args['message'], $current_language );
        $args['message'] = $translate_message['content'];
	}
	return $args;
}

add_filter( 'wp_mail', 'wp_mail_smtp_weglot', PHP_INT_MAX );

Last updated