diff --git a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php index 8e422b5b2c708..2114efd2d3803 100644 --- a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php +++ b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php @@ -14,6 +14,7 @@ use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; use Joomla\CMS\Helper\UserGroupsHelper; +use Joomla\CMS\Language\LanguageFactoryInterface; use Joomla\CMS\Mail\MailHelper; use Joomla\CMS\Mail\MailTemplate; use Joomla\CMS\MVC\Model\BaseDatabaseModel; @@ -71,9 +72,8 @@ public function sendNotification($type, $oldVersion, $newVersion): void $emailReceivers = $this->getEmailReceivers($superUserGroups); } - $app = Factory::getApplication(); - $jLanguage = $app->getLanguage(); - $sitename = $app->get('sitename'); + $app = Factory::getApplication(); + $sitename = $app->get('sitename'); $substitutions = [ 'oldversion' => $oldVersion, @@ -82,17 +82,44 @@ public function sendNotification($type, $oldVersion, $newVersion): void 'url' => Uri::root(), ]; + // Determine the default admin language and load the language file for the fallback and default language + $defaultLocale = ComponentHelper::getParams('com_languages')->get('administrator', 'en-GB'); + $defaultLanguage = $app->getLanguage(); + $defaultLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, 'en-GB', true, true); + $defaultLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR); + // Send emails to all receivers foreach ($emailReceivers as $receiver) { - $params = new Registry($receiver->params); - $jLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, 'en-GB', true, true); - $jLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, $params->get('admin_language', null), true, true); + $receiverParams = new Registry($receiver->params); + $receiverLocale = $receiverParams->get('admin_language', $defaultLocale); + + // Temporarily set application language to user's language. + if ($app->getLanguage()->getTag() !== $receiverLocale) { + $receiverLanguage = Factory::getContainer() + ->get(LanguageFactoryInterface::class) + ->createLanguage($receiverLocale, $app->get('debug_lang', false)); + + Factory::$language = $receiverLanguage; + + if (method_exists($app, 'loadLanguage')) { + $app->loadLanguage($receiverLanguage); + } - $mailer = new MailTemplate('com_joomlaupdate.update.' . $type, $jLanguage->getTag()); - $mailer->addRecipient($receiver->email); + $receiverLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, $receiverLocale); + } + + $mailer = new MailTemplate('com_joomlaupdate.update.' . $type, $receiverLocale); + $mailer->addRecipient($receiver->email, $receiver->name); $mailer->addTemplateData($substitutions); $mailer->send(); } + + // Set application language back to default + Factory::$language = $defaultLanguage; + + if (method_exists($app, 'loadLanguage')) { + $app->loadLanguage($defaultLanguage); + } } /** diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a59d8ffa9530b..bef4ff4ded87d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -2091,7 +2091,7 @@ parameters: - message: ''' #^Access to deprecated property \$app of class Joomla\\Component\\Fields\\Administrator\\Plugin\\FieldsPlugin\: - 5.4.0 will be removed in 7\.0 use \$this\-\>getApplication\(\) instead$# + 5\.4\.0 will be removed in 7\.0 use \$this\-\>getApplication\(\) instead$# ''' identifier: property.deprecated count: 1 @@ -3770,6 +3770,18 @@ parameters: count: 1 path: administrator/components/com_joomlaupdate/src/Controller/UpdateController.php + - + message: ''' + #^Access to deprecated static property \$language of class Joomla\\CMS\\Factory\: + 4\.3 will be removed in 6\.0 + Use the language service in the DI container or get from the application object + Example\: + Factory\:\:getApplication\(\)\-\>getLanguage\(\);$# + ''' + identifier: staticProperty.deprecated + count: 2 + path: administrator/components/com_joomlaupdate/src/Model/NotificationModel.php + - message: ''' #^Call to deprecated method get\(\) of class Joomla\\CMS\\Updater\\Update\: @@ -3836,16 +3848,6 @@ parameters: count: 1 path: administrator/components/com_joomlaupdate/src/Model/UpdateModel.php - - - message: ''' - #^Call to method getDispatcher\(\) of deprecated interface Joomla\\CMS\\Application\\EventAwareInterface\: - 4\.3 will be removed in 7\.0 - This interface will be removed without replacement as the Joomla 3\.x compatibility layer will be removed$# - ''' - identifier: method.deprecatedInterface - count: 2 - path: administrator/components/com_joomlaupdate/src/Model/UpdateModel.php - - message: ''' #^Call to method set\(\) of deprecated class Joomla\\CMS\\Adapter\\Adapter\: