<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[59592] trunk: I18N: Mail: Make PHPMailer messages translatable.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/59592">59592</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/59592","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>swissspidy</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2025-01-08 12:52:04 +0000 (Wed, 08 Jan 2025)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>I18N: Mail: Make PHPMailer messages translatable.
Adds a new `WP_PHPMailer` class to leverage the WordPress i18n system with PHPMailer, so that any user-visible error messages can be properly translated.
Props sukhendu2002, swissspidy, audrasjb, iandunn, nacin, mark-k.
Fixes <a href="https://core.trac.wordpress.org/ticket/23311">#23311</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswplocaleswitcherphp">trunk/src/wp-includes/class-wp-locale-switcher.php</a></li>
<li><a href="#trunksrcwpincludespluggablephp">trunk/src/wp-includes/pluggable.php</a></li>
<li><a href="#trunktestsphpunitdatalanguagesde_DEl10nphp">trunk/tests/phpunit/data/languages/de_DE.l10n.php</a></li>
<li><a href="#trunktestsphpunitdatalanguagesde_DEmo">trunk/tests/phpunit/data/languages/de_DE.mo</a></li>
<li><a href="#trunktestsphpunitdatalanguagesde_DEpo">trunk/tests/phpunit/data/languages/de_DE.po</a></li>
<li><a href="#trunktestsphpunitincludesbootstrapphp">trunk/tests/phpunit/includes/bootstrap.php</a></li>
<li><a href="#trunktestsphpunitincludesmockmailerphp">trunk/tests/phpunit/includes/mock-mailer.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswpphpmailerphp">trunk/src/wp-includes/class-wp-phpmailer.php</a></li>
<li><a href="#trunktestsphpunittestsl10nphpmailerTranslationsphp">trunk/tests/phpunit/tests/l10n/phpmailerTranslations.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclasswplocaleswitcherphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-locale-switcher.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-locale-switcher.php 2025-01-08 12:34:17 UTC (rev 59591)
+++ trunk/src/wp-includes/class-wp-locale-switcher.php 2025-01-08 12:52:04 UTC (rev 59592)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -273,11 +273,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.7.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @global WP_Locale $wp_locale WordPress date and time locale object.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @global PHPMailer\PHPMailer\PHPMailer $phpmailer
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $locale The locale to change to.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private function change_locale( $locale ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- global $wp_locale;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ global $wp_locale, $phpmailer;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->load_translations( $locale );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -285,6 +286,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> WP_Translation_Controller::get_instance()->set_locale( $locale );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $phpmailer instanceof WP_PHPMailer ) {
+ $phpmailer->SetLanguage();
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Fires when the locale is switched to or restored.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpphpmailerphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/src/wp-includes/class-wp-phpmailer.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-phpmailer.php (rev 0)
+++ trunk/src/wp-includes/class-wp-phpmailer.php 2025-01-08 12:52:04 UTC (rev 59592)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,93 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * WordPress PHPMailer class.
+ *
+ * @package WordPress
+ * @since 6.8.0
+ */
+
+/**
+ * WordPress PHPMailer class.
+ *
+ * Overrides the internationalization method in order to use WordPress' instead.
+ *
+ * @since 6.8.0
+ */
+class WP_PHPMailer extends PHPMailer\PHPMailer\PHPMailer {
+
+ /**
+ * Constructor.
+ *
+ * @since 6.8.0
+ *
+ * @param bool $exceptions Optional. Whether to throw exceptions for errors. Default false.
+ */
+ public function __construct( $exceptions = false ) {
+ parent::__construct( $exceptions );
+ $this->SetLanguage();
+ }
+
+ /**
+ * Defines the error messages using WordPress' internationalization method.
+ *
+ * @since 6.8.0
+ *
+ * @return true Always returns true.
+ */
+ public function SetLanguage( $langcode = 'en', $lang_path = '' ) {
+ $error_strings = array(
+ 'authenticate' => __( 'SMTP Error: Could not authenticate.' ),
+ 'buggy_php' => sprintf(
+ /* translators: 1: mail.add_x_header. 2: php.ini */
+ __(
+ 'Your version of PHP is affected by a bug that may result in corrupted messages. To fix it, switch to sending using SMTP, disable the %1$s option in your %2$s, or switch to MacOS or Linux, or upgrade your PHP version.'
+ ),
+ 'mail.add_x_header',
+ 'php.ini'
+ ),
+ 'connect_host' => __( 'SMTP Error: Could not connect to SMTP host.' ),
+ 'data_not_accepted' => __( 'SMTP Error: data not accepted.' ),
+ 'empty_message' => __( 'Message body empty' ),
+ /* translators: There is a space after the colon. */
+ 'encoding' => __( 'Unknown encoding: ' ),
+ /* translators: There is a space after the colon. */
+ 'execute' => __( 'Could not execute: ' ),
+ /* translators: There is a space after the colon. */
+ 'extension_missing' => __( 'Extension missing: ' ),
+ /* translators: There is a space after the colon. */
+ 'file_access' => __( 'Could not access file: ' ),
+ /* translators: There is a space after the colon. */
+ 'file_open' => __( 'File Error: Could not open file: ' ),
+ /* translators: There is a space after the colon. */
+ 'from_failed' => __( 'The following From address failed: ' ),
+ 'instantiate' => __( 'Could not instantiate mail function.' ),
+ /* translators: There is a space after the colon. */
+ 'invalid_address' => __( 'Invalid address: ' ),
+ 'invalid_header' => __( 'Invalid header name or value' ),
+ /* translators: There is a space after the colon. */
+ 'invalid_hostentry' => __( 'Invalid hostentry: ' ),
+ /* translators: There is a space after the colon. */
+ 'invalid_host' => __( 'Invalid host: ' ),
+ /* translators: There is a space at the beginning. */
+ 'mailer_not_supported' => __( ' mailer is not supported.' ),
+ 'provide_address' => __( 'You must provide at least one recipient email address.' ),
+ /* translators: There is a space after the colon. */
+ 'recipients_failed' => __( 'SMTP Error: The following recipients failed: ' ),
+ /* translators: There is a space after the colon. */
+ 'signing' => __( 'Signing Error: ' ),
+ /* translators: There is a space after the colon. */
+ 'smtp_code' => __( 'SMTP code: ' ),
+ /* translators: There is a space after the colon. */
+ 'smtp_code_ex' => __( 'Additional SMTP info: ' ),
+ 'smtp_connect_failed' => __( 'SMTP connect() failed.' ),
+ /* translators: There is a space after the colon. */
+ 'smtp_detail' => __( 'Detail: ' ),
+ /* translators: There is a space after the colon. */
+ 'smtp_error' => __( 'SMTP server error: ' ),
+ /* translators: There is a space after the colon. */
+ 'variable_set' => __( 'Cannot set or reset variable: ' ),
+ );
+ $this->language = $error_strings;
+ return true;
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/src/wp-includes/class-wp-phpmailer.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunksrcwpincludespluggablephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/pluggable.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/pluggable.php 2025-01-08 12:34:17 UTC (rev 59591)
+++ trunk/src/wp-includes/pluggable.php 2025-01-08 12:52:04 UTC (rev 59592)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -251,7 +251,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $phpmailer = new PHPMailer\PHPMailer\PHPMailer( true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ require_once ABSPATH . WPINC . '/class-wp-phpmailer.php';
+ $phpmailer = new WP_PHPMailer( true );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $phpmailer::$validator = static function ( $email ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return (bool) is_email( $email );
</span></span></pre></div>
<a id="trunktestsphpunitdatalanguagesde_DEl10nphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/data/languages/de_DE.l10n.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/languages/de_DE.l10n.php 2025-01-08 12:34:17 UTC (rev 59591)
+++ trunk/tests/phpunit/data/languages/de_DE.l10n.php 2025-01-08 12:52:04 UTC (rev 59592)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,2 +1,2 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-return ['domain'=>NULL,'plural-forms'=>'nplurals=2; plural=n != 1;','messages'=>['html_lang_attribute'=>'de-DE','text directionltr'=>'ltr','number_format_decimal_point'=>',','number_format_thousands_sep'=>'.','Update %s now'=>'Jetzt %s aktualisieren','[%1$s] Confirm Action: %2$s'=>'[%1$s] Aktion bestätigen: %2$s','[%s] Erasure Request Fulfilled'=>'[%s] Löschauftrag ausgeführt','[%s] Personal Data Export'=>'[%s] Export personenbezogener Daten'],'language'=>'de_DE','x-generator'=>'Poedit 2.2.1'];
</del><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+return ['domain'=>NULL,'plural-forms'=>'nplurals=2; plural=n != 1;','messages'=>['html_lang_attribute'=>'de-DE','text directionltr'=>'ltr','number_format_decimal_point'=>',','number_format_thousands_sep'=>'.','Update %s now'=>'Jetzt %s aktualisieren','[%1$s] Confirm Action: %2$s'=>'[%1$s] Aktion bestätigen: %2$s','[%s] Erasure Request Fulfilled'=>'[%s] Löschauftrag ausgeführt','[%s] Personal Data Export'=>'[%s] Export personenbezogener Daten', 'You must provide at least one recipient email address.'=>'Du musst mindestens eine Empfänger-E-Mail-Adresse angeben.'],'language'=>'de_DE','x-generator'=>'Poedit 2.2.1'];
</ins></span></pre></div>
<a id="trunktestsphpunitdatalanguagesde_DEmo"></a>
<div class="binary"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/data/languages/de_DE.mo</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<a id="trunktestsphpunitdatalanguagesde_DEpo"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/data/languages/de_DE.po</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/data/languages/de_DE.po 2025-01-08 12:34:17 UTC (rev 59591)
+++ trunk/tests/phpunit/data/languages/de_DE.po 2025-01-08 12:52:04 UTC (rev 59592)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -57,3 +57,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> #: wp-admin/includes/file.php:2415
</span><span class="cx" style="display: block; padding: 0 10px"> msgid "[%s] Personal Data Export"
</span><span class="cx" style="display: block; padding: 0 10px"> msgstr "[%s] Export personenbezogener Daten"
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+#: wp-includes/class-wp-phpmailer.php:71
+msgid "You must provide at least one recipient email address."
+msgstr "Du musst mindestens eine Empfänger-E-Mail-Adresse angeben."
</ins></span></pre></div>
<a id="trunktestsphpunitincludesbootstrapphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/bootstrap.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/bootstrap.php 2025-01-08 12:34:17 UTC (rev 59591)
+++ trunk/tests/phpunit/includes/bootstrap.php 2025-01-08 12:52:04 UTC (rev 59592)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -246,10 +246,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $multisite = $multisite || ( defined( 'WP_TESTS_MULTISITE' ) && WP_TESTS_MULTISITE );
</span><span class="cx" style="display: block; padding: 0 10px"> $multisite = $multisite || ( defined( 'MULTISITE' ) && MULTISITE );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-// Override the PHPMailer.
-require_once __DIR__ . '/mock-mailer.php';
-$phpmailer = new MockPHPMailer( true );
-
</del><span class="cx" style="display: block; padding: 0 10px"> if ( ! defined( 'WP_DEFAULT_THEME' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> define( 'WP_DEFAULT_THEME', 'default' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -305,6 +301,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Load WordPress.
</span><span class="cx" style="display: block; padding: 0 10px"> require_once ABSPATH . 'wp-settings.php';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Override the PHPMailer.
+require_once __DIR__ . '/mock-mailer.php';
+
+$phpmailer = new MockPHPMailer( true );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Delete any default posts & related data.
</span><span class="cx" style="display: block; padding: 0 10px"> _delete_all_posts();
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunktestsphpunitincludesmockmailerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/mock-mailer.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/mock-mailer.php 2025-01-08 12:34:17 UTC (rev 59591)
+++ trunk/tests/phpunit/includes/mock-mailer.php 2025-01-08 12:52:04 UTC (rev 59592)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,8 +1,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/**
+ * Mock PHPMailer class for testing.
+ *
+ * @package WordPress
+ * @subpackage UnitTests
+ * @since 4.5.0
+ */
+
</ins><span class="cx" style="display: block; padding: 0 10px"> require_once ABSPATH . 'wp-includes/PHPMailer/PHPMailer.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require_once ABSPATH . 'wp-includes/PHPMailer/Exception.php';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+require_once ABSPATH . 'wp-includes/class-wp-phpmailer.php';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-class MockPHPMailer extends PHPMailer\PHPMailer\PHPMailer {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/**
+ * Test class extending WP_PHPMailer.
+ *
+ * @since 4.5.0
+ */
+class MockPHPMailer extends WP_PHPMailer {
</ins><span class="cx" style="display: block; padding: 0 10px"> public $mock_sent = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public function preSend() {
</span></span></pre></div>
<a id="trunktestsphpunittestsl10nphpmailerTranslationsphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/l10n/phpmailerTranslations.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/l10n/phpmailerTranslations.php (rev 0)
+++ trunk/tests/phpunit/tests/l10n/phpmailerTranslations.php 2025-01-08 12:52:04 UTC (rev 59592)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,66 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Unit tests covering PHPMailer translations.
+ *
+ * @package WordPress
+ * @subpackage PHPMailer
+ * @since 6.8.0
+ */
+
+/**
+ * Class Test_PHPMailer_Translations.
+ *
+ * Provides tests for PHPMailer translations.
+ *
+ * @group mail
+ * @group i18n
+ * @group l10n
+ *
+ * @since 6.8.0
+ */
+class Test_PHPMailer_Translations extends WP_UnitTestCase {
+ /**
+ * Tests that PHPMailer error message translation works as expected.
+ *
+ * @ticket 23311
+ */
+ public function test_missing_recipient_error_message_should_be_translated() {
+ reset_phpmailer_instance();
+
+ $is_switched = switch_to_locale( 'de_DE' );
+
+ $phpmailer = tests_retrieve_phpmailer_instance();
+ $phpmailer->setFrom( 'invalid-email@example.com' );
+
+ try {
+ $phpmailer->send();
+ $this->fail( 'Expected exception was not thrown' );
+ } catch ( PHPMailer\PHPMailer\Exception $e ) {
+ $error_message = $e->getMessage();
+ } finally {
+ if ( $is_switched ) {
+ restore_previous_locale();
+ }
+ }
+
+ $this->assertSame(
+ 'Du musst mindestens eine Empfänger-E-Mail-Adresse angeben.',
+ $error_message,
+ 'Error message is not translated as expected'
+ );
+ }
+
+ /**
+ * Test that PHPMailer error message keys are consistent across implementations.
+ *
+ * @ticket 23311
+ */
+ public function test_all_error_message_keys_should_be_translated() {
+ reset_phpmailer_instance();
+
+ $phpmailer = new PHPMailer\PHPMailer\PHPMailer();
+ $wp_phpmailer = tests_retrieve_phpmailer_instance();
+
+ $this->assertEqualSets( array_keys( $phpmailer->GetTranslations() ), array_keys( $wp_phpmailer->GetTranslations() ) );
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/l10n/phpmailerTranslations.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span></div>
</body>
</html>