diff --git a/dgi_fixity.module b/dgi_fixity.module index 8d5b84e..289a5e0 100644 --- a/dgi_fixity.module +++ b/dgi_fixity.module @@ -78,13 +78,15 @@ function dgi_fixity_mail($key, &$message, $params) { return; } + $options = ['langcode' => $message['langcode']]; $now = \Drupal::time()->getRequestTime(); - $subject = \t('Fixity Check Report - @now', ['@now' => date(DATE_RFC7231, $now)])->render(); - $body = $fixity->summary($stats); + $subject = \t('Fixity Check Report - @now', ['@now' => date(DATE_RFC7231, $now)], $options)->render(); + $body = $fixity->summary($stats, $options); if ($stats['failed'] !== 0) { $body[] = \t( 'There are failed checks which require your attention please review the current state of checks here.', - ['@site' => Url::fromRoute('entity.fixity_check.collection', [], ['absolute' => TRUE])->toString()] + ['@site' => Url::fromRoute('entity.fixity_check.collection', [], ['absolute' => TRUE])->toString()], + $options )->render(); } @@ -130,7 +132,7 @@ function dgi_fixity_cron() { $uid = $settings->get(SettingsForm::NOTIFY_USER); $user = User::load($uid); if ($user) { - \Drupal::service('plugin.manager.mail')->mail('dgi_fixity', 'notify', $user->getEmail(), $user->getPreferredAdminLangcode(TRUE)); + \Drupal::service('plugin.manager.mail')->mail('dgi_fixity', 'notify', $user->getEmail(), $user->getPreferredLangcode(TRUE)); } } diff --git a/src/FixityCheckService.php b/src/FixityCheckService.php index 5cbb54d..104598d 100644 --- a/src/FixityCheckService.php +++ b/src/FixityCheckService.php @@ -346,28 +346,36 @@ class FixityCheckService implements FixityCheckServiceInterface { /** * {@inheritdoc} */ - public function summary(array $stats): array { + public function summary(array $stats, array $options = []): array { $summary = []; $summary[] = $this->formatPlural( $stats['revisions'], '@count check has been performed since tracking started.', '@count checks have been performed since tracking started.', + [], + $options ); $summary[] = $this->formatPlural( $stats['periodic']['total'], '@count file is set to be checked periodically.', '@count files are set to be checked periodically.', + [], + $options ); $summary[] = $this->formatPlural( $stats['periodic']['current'], '@count periodic check is up to date.', '@count periodic checks are up to date.', + [], + $options ); if ($stats['periodic']['expired'] > 0) { $summary[] = $this->formatPlural( $stats['periodic']['expired'], '@count periodic check is out to date.', '@count periodic checks are out to date.', + [], + $options ); } if ($stats['failed'] > 0) { @@ -375,12 +383,16 @@ class FixityCheckService implements FixityCheckServiceInterface { $stats['failed'], '@count check has failed.', '@count checks have failed.', + [], + $options ); foreach ($stats['states'] as $state => $count) { $summary[] = $this->formatPlural( $count, FixityCheck::getStateProperty($state, 'singular'), FixityCheck::getStateProperty($state, 'plural'), + [], + $options ); } } diff --git a/src/FixityCheckServiceInterface.php b/src/FixityCheckServiceInterface.php index d48a680..c719418 100644 --- a/src/FixityCheckServiceInterface.php +++ b/src/FixityCheckServiceInterface.php @@ -125,10 +125,12 @@ interface FixityCheckServiceInterface { * * @param array $stats * The stats as returned by this service. + * @param array $options + * An associative array of additional options for the TranslatableMarkup. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup[] * A list of messages that describe the current state of the system. */ - public function summary(array $stats): array; + public function summary(array $stats, array $options = []): array; }