Make WordPress Core

Opened 12 years ago

Closed 2 weeks ago

Last modified 2 weeks ago

#23311 closed enhancement (fixed)

Enable internationalization in PHPMailer

Reported by: iandunn's profile iandunn Owned by: swissspidy's profile swissspidy
Milestone: 6.8 Priority: normal
Severity: normal Version: 3.5
Component: I18N Keywords: has-patch needs-unit-tests
Focuses: Cc:

Description

Per the discussion in #23291, we should enable PHPMailer's internationalization feature so that any error messages returned by it and displayed to the user will be translated.

Attachments (4)

23311.diff (2.0 KB) - added by iandunn 12 years ago.
23311.2.diff (2.8 KB) - added by iandunn 12 years ago.
Creates new class extending PHPMailer
23311.2-unit-tests.diff (784 bytes) - added by iandunn 12 years ago.
23311.2.2.diff (2.9 KB) - added by iandunn 12 years ago.
Updated for PHPMailer 5.2.4

Download all attachments as: .zip

Change History (22)

#1 @mark-k
12 years ago

  • Cc mark@… added

#2 @SergeyBiryukov
12 years ago

  • Version changed from trunk to 3.5

@iandunn
12 years ago

#3 @iandunn
12 years ago

  • Keywords has-patch needs-codex added

I've attached a patch for this. #23291 will need to be committed for this to have any effect, though, since currently wp_mail() ignores any errors that PHPMailer throws.

If this gets committed, we'll need to update the Codex to tell users how to install the PHPMailer localizations that match the version of PHPMailer shipped with Core.

It'd also be good to have the PHPMailer localizations ship with the localized versions of WP (e.g., http://fr.wordpress.org/, etc). What would be the best way to approach that? Is there a team that maintains those, or is it just random contributors?

#4 follow-ups: @nacin
12 years ago

  • Milestone changed from Awaiting Review to 3.6

What we can do instead is add every string in PHPMailer::SetLanguage to the WordPress POT file, so it may be translated like any other string in WordPress.

Then, we can set $phpmailer->language directly, with our own strings.

As $phpmailer->language is protected, it would probably make the most sense to actually extend PHPMailer and create a WP_PHPMailer class.

Unit tests should then test that we are not missing any strings in WP_PHPMailer that are present in a potential future version of PHPMailer, by confirming that the keys returned by PHPMailer::GetTranslations() line up.

Or, to involve upstream, we can submit a change upstream to allow for the language strings to be set from an array, rather than from a PHP file. Then implement that change downstream and leverage it here. I would not be surprised, though, if the comment from upstream is to simply extend PHPMailer.

#5 @nacin
12 years ago

  • Keywords needs-codex removed

#6 in reply to: ↑ 4 ; follow-up: @mark-k
12 years ago

Replying to nacin:
Can't we do

$phpmailer->SetLanguage( 'wp', ABSPATH . WPINC .'/' ) ); 

and add a file named phpmailer.lang-wp.php to wp-includes which looks like

    $PHPMAILER_LANG = array(
      'provide_address' => __('You must provide at least one recipient email address.'),
      'mailer_not_supported' => __(' mailer is not supported.'),
      'execute' => __('Could not execute: '),
       ....
    );

#7 in reply to: ↑ 6 @nacin
12 years ago

Replying to mark-k:

Replying to nacin:
Can't we do

$phpmailer->SetLanguage( 'wp', ABSPATH . WPINC .'/' ) ); 

and add a file named phpmailer.lang-wp.php to wp-includes which looks like

    $PHPMAILER_LANG = array(
      'provide_address' => __('You must provide at least one recipient email address.'),
      'mailer_not_supported' => __(' mailer is not supported.'),
      'execute' => __('Could not execute: '),
       ....
    );

Looks like that would work too. It does abuse the $langcode parameter, but that is only used for the include().

@iandunn
12 years ago

Creates new class extending PHPMailer

#8 in reply to: ↑ 4 @iandunn
12 years ago

Replying to nacin:

What we can do instead is add every string in PHPMailer::SetLanguage to the WordPress POT file, so it may be translated like any other string in WordPress.

Then, we can set $phpmailer->language directly, with our own strings.

As $phpmailer->language is protected, it would probably make the most sense to actually extend PHPMailer and create a WP_PHPMailer class.

Unit tests should then test that we are not missing any strings in WP_PHPMailer that are present in a potential future version of PHPMailer, by confirming that the keys returned by PHPMailer::GetTranslations() line up.

That's done in 23311.2.diff and 23311.2-unit-tests.diff.

@iandunn
12 years ago

Updated for PHPMailer 5.2.4

#9 @iandunn
12 years ago

PHPMailer was updated from 5.2.1 to 5.2.4 in #21074 and the $PHPMAILER_LANG keys changed a bit. 23311.2.2.diff is updated to reflect the changes.

#10 @ryan
12 years ago

  • Milestone changed from 3.6 to Future Release

#11 @chriscct7
9 years ago

  • Severity changed from minor to normal

#12 @desrosj
4 years ago

  • Keywords needs-refresh added
  • Milestone set to Future Release

This came up in the comments of a recent call for testing after a recent PHPMailer update.

The patch here will definitely need a refresh

#13 @swissspidy
2 months ago

  • Milestone changed from Future Release to 6.8
  • Owner set to swissspidy
  • Status changed from new to assigned

This ticket was mentioned in PR #7937 on WordPress/wordpress-develop by @sukhendu2002.


7 weeks ago
#14

  • Keywords has-unit-tests added; needs-refresh removed

#15 @swissspidy
7 weeks ago

  • Keywords needs-unit-tests added; has-unit-tests removed

@swissspidy commented on PR #7937:


6 weeks ago
#16

@Sukhendu2002 I took the liberty to push some changes, simplifying the locale switching in the test.

When switching locales we need to ensure that the global PHPMailer instance's translations are updated. This should be achieved in WP_Locale_Switcher, not by resetting the instance in the test.

#17 @swissspidy
2 weeks ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 59592:

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.

Note: See TracTickets for help on using tickets.