diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index 2b4473b27c..13636aa00b 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -1726,10 +1726,14 @@ function install_download_additional_translations_operations(&$install_state) {
*/
function install_import_translations(&$install_state) {
\Drupal::moduleHandler()->loadInclude('locale', 'translation.inc');
+ \Drupal::moduleHandler()->loadInclude('locale', 'batch.inc');
// If there is more than one language or the single one is not English, we
// should import translations.
- $operations = install_download_additional_translations_operations($install_state);
+ $operations = array_merge(
+ ['locale_batch_store_finish_feedback', [FALSE]],
+ install_download_additional_translations_operations($install_state)
+ );
$languages = \Drupal::languageManager()->getLanguages();
if (count($languages) > 1 || !isset($languages['en'])) {
$operations[] = ['_install_prepare_import', [array_keys($languages), $install_state['server_pattern']]];
@@ -1749,27 +1753,13 @@ function install_import_translations(&$install_state) {
'title' => t('Updating translations.'),
'progress_message' => '',
'error_message' => t('Error importing translation files'),
- 'finished' => '_install_locale_translation_batch_fetch_finished',
+ 'finished' => 'locale_translation_batch_fetch_finished',
'file' => drupal_get_path('module', 'locale') . '/locale.batch.inc',
];
return $batch;
}
}
-/**
- * Implements callback_batch_finished().
- *
- * @param bool $success
- * TRUE if batch successfully completed.
- * @param array $results
- * Batch results.
- */
-function _install_locale_translation_batch_fetch_finished($success, $results) {
- if ($success) {
- \Drupal::state()->set('locale.translation_last_checked', REQUEST_TIME);
- }
-}
-
/**
* Tells the translation import process that Drupal core is installed.
*
diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc
index 3feee12c5b..c11ca31781 100644
--- a/core/modules/locale/locale.bulk.inc
+++ b/core/modules/locale/locale.bulk.inc
@@ -138,7 +138,9 @@ function locale_translate_batch_build(array $files, array $options) {
'finish_feedback' => TRUE,
];
if (count($files)) {
- $operations = [];
+ $operations = [
+ ['locale_batch_store_finish_feedback', [$options['finish_feedback']]],
+ ];
foreach ($files as $file) {
// We call locale_translate_batch_import for every batch operation.
$operations[] = ['locale_translate_batch_import', [$file, $options]];
@@ -155,10 +157,8 @@ function locale_translate_batch_build(array $files, array $options) {
'progress_message' => '',
'error_message' => t('Error importing interface translations'),
'file' => drupal_get_path('module', 'locale') . '/locale.bulk.inc',
+ 'finished' => 'locale_translate_batch_finished',
];
- if ($options['finish_feedback']) {
- $batch['finished'] = 'locale_translate_batch_finished';
- }
return $batch;
}
return FALSE;
@@ -365,7 +365,7 @@ function locale_translate_batch_finished($success, array $results) {
$logger = \Drupal::logger('locale');
if ($success) {
$additions = $updates = $deletes = $skips = $config = 0;
- if (isset($results['failed_files'])) {
+ if (isset($results['failed_files']) && $results['finish_feedback']) {
if (\Drupal::moduleHandler()->moduleExists('dblog') && \Drupal::currentUser()->hasPermission('access site reports')) {
$message = \Drupal::translation()->formatPlural(count($results['failed_files']), 'One translation file could not be imported. See the log for details.', '@count translation files could not be imported. See the log for details.', [':url' => \Drupal::url('dblog.overview')]);
}
@@ -389,21 +389,25 @@ function locale_translate_batch_finished($success, array $results) {
}
}
}
- \Drupal::messenger()->addStatus(\Drupal::translation()->formatPlural(count($results['files']),
- 'One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.',
- '@count translation files imported. %number translations were added, %update translations were updated and %delete translations were removed.',
- ['%number' => $additions, '%update' => $updates, '%delete' => $deletes]
- ));
+ if ($results['finish_feedback']) {
+ \Drupal::messenger()->addStatus(\Drupal::translation()->formatPlural(count($results['files']),
+ 'One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.',
+ '@count translation files imported. %number translations were added, %update translations were updated and %delete translations were removed.',
+ ['%number' => $additions, '%update' => $updates, '%delete' => $deletes]
+ ));
+ }
$logger->notice('Translations imported: %number added, %update updated, %delete removed.', ['%number' => $additions, '%update' => $updates, '%delete' => $deletes]);
if ($skips) {
- if (\Drupal::moduleHandler()->moduleExists('dblog') && \Drupal::currentUser()->hasPermission('access site reports')) {
- $message = \Drupal::translation()->formatPlural($skips, 'One translation string was skipped because of disallowed or malformed HTML. See the log for details.', '@count translation strings were skipped because of disallowed or malformed HTML. See the log for details.', [':url' => \Drupal::url('dblog.overview')]);
- }
- else {
- $message = \Drupal::translation()->formatPlural($skips, 'One translation string was skipped because of disallowed or malformed HTML. See the log for details.', '@count translation strings were skipped because of disallowed or malformed HTML. See the log for details.');
+ if ($results['finish_feedback']) {
+ if (\Drupal::moduleHandler()->moduleExists('dblog') && \Drupal::currentUser()->hasPermission('access site reports')) {
+ $message = \Drupal::translation()->formatPlural($skips, 'One translation string was skipped because of disallowed or malformed HTML. See the log for details.', '@count translation strings were skipped because of disallowed or malformed HTML. See the log for details.', [':url' => \Drupal::url('dblog.overview')]);
+ }
+ else {
+ $message = \Drupal::translation()->formatPlural($skips, 'One translation string was skipped because of disallowed or malformed HTML. See the log for details.', '@count translation strings were skipped because of disallowed or malformed HTML. See the log for details.');
+ }
+ \Drupal::messenger()->addWarning($message);
}
- \Drupal::messenger()->addWarning($message);
$logger->warning('@count disallowed HTML string(s) in files: @files.', ['@count' => $skips, '@files' => implode(',', $skipped_files)]);
}
}
@@ -559,7 +563,9 @@ function locale_config_batch_build(array $names, array $langcodes, array $option
$options += ['finish_feedback' => TRUE];
$i = 0;
$batch_names = [];
- $operations = [];
+ $operations = [
+ ['locale_batch_store_finish_feedback', [$options['finish_feedback']]],
+ ];
foreach ($names as $name) {
$batch_names[] = $name;
$i++;
@@ -581,13 +587,28 @@ function locale_config_batch_build(array $names, array $langcodes, array $option
'init_message' => t('Starting configuration update'),
'error_message' => t('Error updating configuration translations'),
'file' => drupal_get_path('module', 'locale') . '/locale.bulk.inc',
+ 'finished' => 'locale_config_batch_finished',
];
- if (!empty($options['finish_feedback'])) {
- $batch['completed'] = 'locale_config_batch_finished';
- }
return $batch;
}
+/**
+ * Implements callback_batch_operation().
+ *
+ * Stores the finish_feedback value in batch results for use in the finish
+ * callback.
+ *
+ * @param bool $finish_feedback
+ * Whether user feedback should be provided at the end of the batch.
+ * @param array|\ArrayAccess $context
+ * The batch context.
+ *
+ * @see locale_config_batch_build()
+ */
+function locale_batch_store_finish_feedback($finish_feedback, &$context) {
+ $context['results']['finish_feedback'] = $finish_feedback;
+}
+
/**
* Implements callback_batch_operation().
*
@@ -617,7 +638,7 @@ function locale_config_batch_refresh_name(array $names, array $langcodes, &$cont
/**
* Implements callback_batch_finished().
*
- * Finishes callback of system page locale import batch.
+ * Finished callback of system page locale import batch.
*
* @param bool $success
* Information about the success of the batch import.
@@ -630,11 +651,15 @@ function locale_config_batch_finished($success, array $results) {
if ($success) {
$configuration = isset($results['stats']['config']) ? $results['stats']['config'] : 0;
if ($configuration) {
- \Drupal::messenger()->addStatus(t('The configuration was successfully updated. There are %number configuration objects updated.', ['%number' => $configuration]));
+ if ($results['finish_feedback']) {
+ \Drupal::messenger()->addStatus(t('The configuration was successfully updated. There are %number configuration objects updated.', ['%number' => $configuration]));
+ }
\Drupal::logger('locale')->notice('The configuration was successfully updated. %number configuration objects updated.', ['%number' => $configuration]);
}
else {
- \Drupal::messenger()->addStatus(t('No configuration objects have been updated.'));
+ if ($results['finish_feedback']) {
+ \Drupal::messenger()->addStatus(t('No configuration objects have been updated.'));
+ }
\Drupal::logger('locale')->warning('No configuration objects have been updated.');
}
}