function locale_translate_batch_finished in Zircon Profile 8.0
Same name and namespace in other branches
- 8 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 364 - Mass import-export and batch import functionality for Gettext .po files.
Code
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 (\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.', array(
':url' => \Drupal::url('dblog.overview'),
));
}
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_set_message($message, 'error');
}
if (isset($results['files'])) {
$skipped_files = array();
// 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) {
$additions += $report['additions'];
$updates += $report['updates'];
$deletes += $report['deletes'];
$skips += $report['skips'];
if ($report['skips'] > 0) {
$skipped_files[] = $filepath;
}
}
}
drupal_set_message(\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.', array(
'%number' => $additions,
'%update' => $updates,
'%delete' => $deletes,
)));
$logger
->notice('Translations imported: %number added, %update updated, %delete removed.', array(
'%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.', array(
':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_set_message($message, 'warning');
$logger
->warning('@count disallowed HTML string(s) in files: @files.', array(
'@count' => $skips,
'@files' => implode(',', $skipped_files),
));
}
}
}
// Add messages for configuration too.
if (isset($results['stats']['config'])) {
locale_config_batch_finished($success, $results);
}
}