0
0
mirror of https://github.com/PHPMailer/PHPMailer.git synced 2024-09-19 17:42:14 +02:00

Localization: allow for more text strings to be translated

In a number of places in the code base I came across hard-code error messages, which were not set up to be translatable.

For those I found, I've now fixed this.

Note: I've not added the labels used for logging errors via the `PHPMailer:edebug()` method. If so desired, that could be added in a future iteration.

Existing translation files have not been updated. Translators may need to be pinged before the next release to update the translation(s) they maintain.

Includes a minor tweak to the PHPCS configuration to allow lines in language files to exceed the "120 chars line max" as using concatenation for text strings in translation files will not work with the current way of loading these files and the new "buggy PHP" message is a long text which would result in nearly all translation files throwing the warning.
This commit is contained in:
jrfnl 2021-07-08 11:54:28 +02:00
parent 1a2e462b9d
commit a550adc872
2 changed files with 16 additions and 11 deletions

View File

@ -36,4 +36,7 @@
<exclude name="PHPCompatibility.ParameterValues.NewIDNVariantDefault.NotSet"/> <exclude name="PHPCompatibility.ParameterValues.NewIDNVariantDefault.NotSet"/>
</rule> </rule>
<rule ref="Generic.Files.LineLength.TooLong">
<exclude-pattern>*/language/phpmailer\.lang*\.php$</exclude-pattern>
</rule>
</ruleset> </ruleset>

View File

@ -1510,12 +1510,7 @@ class PHPMailer
&& ini_get('mail.add_x_header') === '1' && ini_get('mail.add_x_header') === '1'
&& stripos(PHP_OS, 'WIN') === 0 && stripos(PHP_OS, 'WIN') === 0
) { ) {
trigger_error( trigger_error($this->lang('buggy_php'), E_USER_WARNING);
'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 mail.add_x_header option in' .
' your php.ini, switch to MacOS or Linux, or upgrade your PHP to version 7.0.17+ or 7.1.3+.',
E_USER_WARNING
);
} }
try { try {
@ -2213,26 +2208,33 @@ class PHPMailer
//Define full set of translatable strings in English //Define full set of translatable strings in English
$PHPMAILER_LANG = [ $PHPMAILER_LANG = [
'authenticate' => 'SMTP Error: Could not authenticate.', 'authenticate' => 'SMTP Error: Could not authenticate.',
'buggy_php' => '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 mail.add_x_header option in' .
' your php.ini, switch to MacOS or Linux, or upgrade your PHP to version 7.0.17+ or 7.1.3+.',
'connect_host' => 'SMTP Error: Could not connect to SMTP host.', 'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
'data_not_accepted' => 'SMTP Error: data not accepted.', 'data_not_accepted' => 'SMTP Error: data not accepted.',
'empty_message' => 'Message body empty', 'empty_message' => 'Message body empty',
'encoding' => 'Unknown encoding: ', 'encoding' => 'Unknown encoding: ',
'execute' => 'Could not execute: ', 'execute' => 'Could not execute: ',
'extension_missing' => 'Extension missing: ',
'file_access' => 'Could not access file: ', 'file_access' => 'Could not access file: ',
'file_open' => 'File Error: Could not open file: ', 'file_open' => 'File Error: Could not open file: ',
'from_failed' => 'The following From address failed: ', 'from_failed' => 'The following From address failed: ',
'instantiate' => 'Could not instantiate mail function.', 'instantiate' => 'Could not instantiate mail function.',
'invalid_address' => 'Invalid address: ', 'invalid_address' => 'Invalid address: ',
'invalid_header' => 'Invalid header name or value',
'invalid_hostentry' => 'Invalid hostentry: ', 'invalid_hostentry' => 'Invalid hostentry: ',
'invalid_host' => 'Invalid host: ', 'invalid_host' => 'Invalid host: ',
'mailer_not_supported' => ' mailer is not supported.', 'mailer_not_supported' => ' mailer is not supported.',
'provide_address' => 'You must provide at least one recipient email address.', 'provide_address' => 'You must provide at least one recipient email address.',
'recipients_failed' => 'SMTP Error: The following recipients failed: ', 'recipients_failed' => 'SMTP Error: The following recipients failed: ',
'signing' => 'Signing Error: ', 'signing' => 'Signing Error: ',
'smtp_code' => 'SMTP code: ',
'smtp_code_ex' => 'Additional SMTP info: ',
'smtp_connect_failed' => 'SMTP connect() failed.', 'smtp_connect_failed' => 'SMTP connect() failed.',
'smtp_detail' => 'Detail: ',
'smtp_error' => 'SMTP server error: ', 'smtp_error' => 'SMTP server error: ',
'variable_set' => 'Cannot set or reset variable: ', 'variable_set' => 'Cannot set or reset variable: ',
'extension_missing' => 'Extension missing: ',
]; ];
if (empty($lang_path)) { if (empty($lang_path)) {
//Calculate an absolute path so it can work if CWD is not here //Calculate an absolute path so it can work if CWD is not here
@ -3947,13 +3949,13 @@ class PHPMailer
if (!empty($lasterror['error'])) { if (!empty($lasterror['error'])) {
$msg .= $this->lang('smtp_error') . $lasterror['error']; $msg .= $this->lang('smtp_error') . $lasterror['error'];
if (!empty($lasterror['detail'])) { if (!empty($lasterror['detail'])) {
$msg .= ' Detail: ' . $lasterror['detail']; $msg .= ' ' . $this->lang('smtp_detail') . $lasterror['detail'];
} }
if (!empty($lasterror['smtp_code'])) { if (!empty($lasterror['smtp_code'])) {
$msg .= ' SMTP code: ' . $lasterror['smtp_code']; $msg .= ' ' . $this->lang('smtp_code') . $lasterror['smtp_code'];
} }
if (!empty($lasterror['smtp_code_ex'])) { if (!empty($lasterror['smtp_code_ex'])) {
$msg .= ' Additional SMTP info: ' . $lasterror['smtp_code_ex']; $msg .= ' ' . $this->lang('smtp_code_ex') . $lasterror['smtp_code_ex'];
} }
} }
} }
@ -4095,7 +4097,7 @@ class PHPMailer
//Ensure name is not empty, and that neither name nor value contain line breaks //Ensure name is not empty, and that neither name nor value contain line breaks
if (empty($name) || strpbrk($name . $value, "\r\n") !== false) { if (empty($name) || strpbrk($name . $value, "\r\n") !== false) {
if ($this->exceptions) { if ($this->exceptions) {
throw new Exception('Invalid header name or value'); throw new Exception($this->lang('invalid_header'));
} }
return false; return false;