function locale_translate_batch_finished
Same name in other branches
- 9 core/modules/locale/locale.bulk.inc \locale_translate_batch_finished()
- 8.9.x core/modules/locale/locale.bulk.inc \locale_translate_batch_finished()
- 11.x core/modules/locale/locale.bulk.inc \locale_translate_batch_finished()
Implements callback_batch_finished().
Finished callback of system page locale import batch.
Parameters
bool $success: TRUE if batch successfully completed.
array $results: Batch results.
1 call to locale_translate_batch_finished()
- locale_translation_batch_fetch_finished in core/
modules/ locale/ locale.batch.inc - Implements callback_batch_finished().
1 string reference to 'locale_translate_batch_finished'
- locale_translate_batch_build in core/
modules/ locale/ locale.bulk.inc - Build a locale batch from an array of files.
File
-
core/
modules/ locale/ locale.bulk.inc, line 368
Code
function locale_translate_batch_finished($success, array $results) {
$logger = \Drupal::logger('locale');
if ($success) {
$additions = $updates = $deletes = $skips = 0;
if (isset($results['failed_files'])) {
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. <a href=":url">See the log</a> for details.', '@count translation files could not be imported. <a href=":url">See the log</a> for details.', [
':url' => Url::fromRoute('dblog.overview')->toString(),
]);
}
else {
$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.');
}
\Drupal::messenger()->addError($message);
}
if (isset($results['files'])) {
$skipped_files = [];
// If there are no results and/or no stats (eg. coping with an empty .po
// file), simply do nothing.
if ($results && isset($results['stats'])) {
foreach ($results['stats'] as $filepath => $report) {
if ($filepath === 'config') {
// Ignore the config entry. It is processed in
// locale_config_batch_finished() below.
continue;
}
$additions += $report['additions'];
$updates += $report['updates'];
$deletes += $report['deletes'];
$skips += $report['skips'];
if ($report['skips'] > 0) {
$skipped_files[] = $filepath;
}
}
}
\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. <a href=":url">See the log</a> for details.', '@count translation strings were skipped because of disallowed or malformed HTML. <a href=":url">See the log</a> for details.', [
':url' => Url::fromRoute('dblog.overview')->toString(),
]);
}
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);
$logger->warning('@count disallowed HTML string(s) in files: @files.', [
'@count' => $skips,
'@files' => implode(',', $skipped_files),
]);
}
}
}
// Add messages for configuration too.
if (isset($results['stats']['config'])) {
locale_config_batch_finished($success, $results);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.