PHPMailer::setLanguage(): make return value consistent
The return value of the method was inconsistent as it could return `true` even when the requested language was not loaded/set. Previously, the method would: * Return `false` when a `$langcode` was matched against the regex, but the file couldn't be loaded. * Return `true` in all other cases, including when a `$langcode` other than `'en'` was passed, but it didn't match the regex, which meant that effectively the requested language was ignored and English was loaded anyway, but the function would still return `true`. This has now been changed to: * Return `true` when the requested language was loaded, whether `'en'` or another language. * Return `false` when the requested language wasn't loaded and the language defaulted to English. Related to https://github.com/PHPMailer/PHPMailer/issues/2418#issuecomment-876240778
This commit is contained in:
parent
5c64f7e2d8
commit
9182613398
|
|
@ -2186,14 +2186,13 @@ class PHPMailer
|
|||
|
||||
/**
|
||||
* Set the language for error messages.
|
||||
* Returns false if it cannot load the language file.
|
||||
* The default language is English.
|
||||
*
|
||||
* @param string $langcode ISO 639-1 2-character language code (e.g. French is "fr")
|
||||
* @param string $lang_path Path to the language file directory, with trailing separator (slash).D
|
||||
* Do not set this from user input!
|
||||
*
|
||||
* @return bool
|
||||
* @return bool Returns true if the requested language was loaded, false otherwise.
|
||||
*/
|
||||
public function setLanguage($langcode = 'en', $lang_path = '')
|
||||
{
|
||||
|
|
@ -2248,11 +2247,14 @@ class PHPMailer
|
|||
//Calculate an absolute path so it can work if CWD is not here
|
||||
$lang_path = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
//Validate $langcode
|
||||
if (!preg_match('/^[a-z]{2}(?:_[a-zA-Z]{2})?$/', $langcode)) {
|
||||
$foundlang = true;
|
||||
if (!preg_match('/^[a-z]{2}(?:_[a-zA-Z]{2})?$/', $langcode) && $langcode !== 'en') {
|
||||
$foundlang = false;
|
||||
$langcode = 'en';
|
||||
}
|
||||
$foundlang = true;
|
||||
|
||||
$lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
|
||||
//There is no English translation file
|
||||
if ('en' !== $langcode) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue