Make WordPress Core

Changeset 59592


Ignore:
Timestamp:
01/08/2025 12:52:04 PM (19 months ago)
Author:
swissspidy
Message:

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 #23311.

Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-locale-switcher.php

    r57350 r59592  
    274274         *
    275275         * @global WP_Locale $wp_locale WordPress date and time locale object.
     276         * @global PHPMailer\PHPMailer\PHPMailer $phpmailer
    276277         *
    277278         * @param string $locale The locale to change to.
    278279         */
    279280        private function change_locale( $locale ) {
    280                 global $wp_locale;
     281                global $wp_locale, $phpmailer;
    281282
    282283                $this->load_translations( $locale );
     
    285286
    286287                WP_Translation_Controller::get_instance()->set_locale( $locale );
     288
     289                if ( $phpmailer instanceof WP_PHPMailer ) {
     290                        $phpmailer->SetLanguage();
     291                }
    287292
    288293                /**
  • trunk/src/wp-includes/pluggable.php

    r59578 r59592  
    252252                        require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
    253253                        require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
    254                         $phpmailer = new PHPMailer\PHPMailer\PHPMailer( true );
     254                        require_once ABSPATH . WPINC . '/class-wp-phpmailer.php';
     255                        $phpmailer = new WP_PHPMailer( true );
    255256
    256257                        $phpmailer::$validator = static function ( $email ) {
  • trunk/tests/phpunit/data/languages/de_DE.l10n.php

    r57639 r59592  
    11<?php
    2 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'];
     2return ['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'];
  • trunk/tests/phpunit/data/languages/de_DE.po

    r48930 r59592  
    5858msgid "[%s] Personal Data Export"
    5959msgstr "[%s] Export personenbezogener Daten"
     60
     61#: wp-includes/class-wp-phpmailer.php:71
     62msgid "You must provide at least one recipient email address."
     63msgstr "Du musst mindestens eine Empfänger-E-Mail-Adresse angeben."
  • trunk/tests/phpunit/includes/bootstrap.php

    r59326 r59592  
    247247$multisite = $multisite || ( defined( 'MULTISITE' ) && MULTISITE );
    248248
    249 // Override the PHPMailer.
    250 require_once __DIR__ . '/mock-mailer.php';
    251 $phpmailer = new MockPHPMailer( true );
    252 
    253249if ( ! defined( 'WP_DEFAULT_THEME' ) ) {
    254250        define( 'WP_DEFAULT_THEME', 'default' );
     
    305301// Load WordPress.
    306302require_once ABSPATH . 'wp-settings.php';
     303
     304// Override the PHPMailer.
     305require_once __DIR__ . '/mock-mailer.php';
     306
     307$phpmailer = new MockPHPMailer( true );
    307308
    308309// Delete any default posts & related data.
  • trunk/tests/phpunit/includes/mock-mailer.php

    r52009 r59592  
    11<?php
     2/**
     3 * Mock PHPMailer class for testing.
     4 *
     5 * @package WordPress
     6 * @subpackage UnitTests
     7 * @since 4.5.0
     8 */
     9
    210require_once ABSPATH . 'wp-includes/PHPMailer/PHPMailer.php';
    311require_once ABSPATH . 'wp-includes/PHPMailer/Exception.php';
     12require_once ABSPATH . 'wp-includes/class-wp-phpmailer.php';
    413
    5 class MockPHPMailer extends PHPMailer\PHPMailer\PHPMailer {
     14/**
     15 * Test class extending WP_PHPMailer.
     16 *
     17 * @since 4.5.0
     18 */
     19class MockPHPMailer extends WP_PHPMailer {
    620        public $mock_sent = array();
    721
Note: See TracChangeset for help on using the changeset viewer.