2011-08-27 22:04:48 +00:00
< ? php
/**
* @ file
* Mass import - export and batch import functionality for Gettext . po files .
*/
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
use Drupal\Core\Batch\BatchBuilder ;
Issue #2244513 by kim.pepper, phenaproxima, 20th, andrei.dincu, beejeebus, Berdir, alexpott, jibran, andypost, larowlan, Chadwick Wood, acbramley, Wim Leers, sun, xjm, YesCT, chx, tim.plunkett: Move the unmanaged file APIs to the file_system service (file.inc)
2019-02-23 22:35:15 +00:00
use Drupal\Core\File\Exception\FileException ;
2014-06-10 16:52:58 +00:00
use Drupal\Core\Language\LanguageInterface ;
2024-04-29 07:35:43 +00:00
use Drupal\Core\Url ;
2013-06-15 08:46:11 +00:00
use Drupal\file\FileInterface ;
2014-11-24 09:46:43 +00:00
use Drupal\locale\Gettext ;
2011-08-27 22:04:48 +00:00
/**
2011-10-29 11:40:09 +00:00
* Prepare a batch to import all translations .
2011-08-27 22:04:48 +00:00
*
2012-08-19 10:46:48 +00:00
* @ param array $options
* An array with options that can have the following elements :
* - 'langcode' : The language code . Optional , defaults to NULL , which means
* that the language will be detected from the name of the files .
* - 'overwrite_options' : Overwrite options array as defined in
* Drupal\locale\PoDatabaseWriter . Optional , defaults to an empty array .
* - 'customized' : Flag indicating whether the strings imported from $file
* are customized translations or come from a community source . Use
* LOCALE_CUSTOMIZED or LOCALE_NOT_CUSTOMIZED . Optional , defaults to
* LOCALE_NOT_CUSTOMIZED .
* - 'finish_feedback' : Whether or not to give feedback to the user when the
* batch is finished . Optional , defaults to TRUE .
2014-10-22 09:58:00 +00:00
* @ param bool $force
2012-06-16 15:16:07 +00:00
* ( optional ) Import all available files , even if they were imported before .
2011-08-27 22:04:48 +00:00
*
2014-10-22 09:58:00 +00:00
* @ return array | bool
* The batch structure , or FALSE if no files are used to build the batch .
*
2011-10-29 11:40:09 +00:00
* @ todo
* Integrate with update status to identify projects needed and integrate
* l10n_update functionality to feed in translation files alike .
2015-05-18 21:08:10 +00:00
* See https :// www . drupal . org / node / 1191488.
2011-08-27 22:04:48 +00:00
*/
2014-10-22 09:58:00 +00:00
function locale_translate_batch_import_files ( array $options , $force = FALSE ) {
2017-03-04 01:20:24 +00:00
$options += [
'overwrite_options' => [],
2012-08-19 10:46:48 +00:00
'customized' => LOCALE_NOT_CUSTOMIZED ,
'finish_feedback' => TRUE ,
2017-03-04 01:20:24 +00:00
];
2012-12-07 18:17:37 +00:00
2012-08-19 10:46:48 +00:00
if ( ! empty ( $options [ 'langcode' ])) {
2017-03-04 01:20:24 +00:00
$langcodes = [ $options [ 'langcode' ]];
2011-11-25 06:22:29 +00:00
}
else {
// If langcode was not provided, make sure to only import files for the
2014-05-04 17:19:57 +00:00
// languages we have added.
2014-03-31 17:29:01 +00:00
$langcodes = array_keys ( \Drupal :: languageManager () -> getLanguages ());
2011-11-25 06:22:29 +00:00
}
2012-12-07 18:17:37 +00:00
2017-03-04 01:20:24 +00:00
$files = locale_translate_get_interface_translation_files ([], $langcodes );
2012-12-07 18:17:37 +00:00
2012-06-16 15:16:07 +00:00
if ( ! $force ) {
2018-09-21 13:01:49 +00:00
$result = \Drupal :: database () -> select ( 'locale_file' , 'lf' )
2017-03-04 01:20:24 +00:00
-> fields ( 'lf' , [ 'langcode' , 'uri' , 'timestamp' ])
2012-06-16 15:16:07 +00:00
-> condition ( 'langcode' , $langcodes )
-> execute ()
-> fetchAllAssoc ( 'uri' );
foreach ( $result as $uri => $info ) {
if ( isset ( $files [ $uri ]) && filemtime ( $uri ) <= $info -> timestamp ) {
2012-07-26 22:07:25 +00:00
// The file is already imported and not changed since the last import.
2012-06-16 15:16:07 +00:00
// Remove it from file list and don't import it again.
unset ( $files [ $uri ]);
}
}
2011-11-25 06:22:29 +00:00
}
2012-08-19 10:46:48 +00:00
return locale_translate_batch_build ( $files , $options );
2011-08-27 22:04:48 +00:00
}
2012-06-16 15:16:07 +00:00
/**
2012-12-07 18:17:37 +00:00
* Get interface translation files present in the translations directory .
2012-06-16 15:16:07 +00:00
*
2012-12-07 18:17:37 +00:00
* @ param array $projects
2014-10-22 09:58:00 +00:00
* ( optional ) Project names from which to get the translation files and
* history . Defaults to all projects .
2012-12-07 18:17:37 +00:00
* @ param array $langcodes
2014-10-22 09:58:00 +00:00
* ( optional ) Language codes from which to get the translation files and
* history . Defaults to all languages .
2012-06-16 15:16:07 +00:00
*
* @ return array
2012-12-07 18:17:37 +00:00
* An array of interface translation files keyed by their URI .
2012-06-16 15:16:07 +00:00
*/
2017-03-04 01:20:24 +00:00
function locale_translate_get_interface_translation_files ( array $projects = [], array $langcodes = []) {
Issue #697946 by voleger, pguillard, pillarsdotnet, andypost, alansaviolobo, alexpott, vaibhavjain, MerryHamster, sja112, kim.pepper, shaktik, ravi.shankar, Pooja Ganjage, daffie, Mile23, legolasbo, joelpittet, almaudoh, xjm, Berdir, scor: Properly deprecate module_load_include() and move it into \Drupal::moduleHandler() service
2022-01-06 10:01:52 +00:00
\Drupal :: moduleHandler () -> loadInclude ( 'locale' , 'inc' , 'locale.compare' );
2017-03-04 01:20:24 +00:00
$files = [];
2012-12-07 18:17:37 +00:00
$projects = $projects ? $projects : array_keys ( locale_translation_get_projects ());
$langcodes = $langcodes ? $langcodes : array_keys ( locale_translatable_language_list ());
// Scan the translations directory for files matching a name pattern
// containing a project name and language code: {project}.{langcode}.po or
// {project}-{version}.{langcode}.po.
// Only files of known projects and languages will be returned.
2013-09-16 03:58:06 +00:00
$directory = \Drupal :: config ( 'locale.settings' ) -> get ( 'translation.path' );
Issue #3035312 by kim.pepper, andypost, martin107, yogeshmpawar, naveenvalecha, pguillard, Berdir, dww, claudiu.cristea, jibran, Mile23: Move file_scan_directory() to file_system service
2019-07-24 10:29:08 +00:00
$result = [];
if ( is_dir ( $directory )) {
$result = \Drupal :: service ( 'file_system' ) -> scanDirectory ( $directory , '![a-z_]+(\-[0-9a-z\.\-\+]+|)\.[^\./]+\.po$!' , [ 'recurse' => FALSE ]);
}
2012-12-07 18:17:37 +00:00
Issue #1496480 by mrf, disasm, kbasarab, pfrenssen, cam8001, typhonius, Letharion, ACF, vijaycs85, heyrocker, Berdir, alexpott: Convert file system settings to the new configuration system.
2013-02-08 23:36:06 +00:00
foreach ( $result as $file ) {
// Update the file object with project name and version from the file name.
$file = locale_translate_file_attach_properties ( $file );
if ( in_array ( $file -> project , $projects )) {
if ( in_array ( $file -> langcode , $langcodes )) {
$files [ $file -> uri ] = $file ;
2012-12-07 18:17:37 +00:00
}
}
2012-09-07 06:26:10 +00:00
}
Issue #1496480 by mrf, disasm, kbasarab, pfrenssen, cam8001, typhonius, Letharion, ACF, vijaycs85, heyrocker, Berdir, alexpott: Convert file system settings to the new configuration system.
2013-02-08 23:36:06 +00:00
2012-12-07 18:17:37 +00:00
return $files ;
2012-06-16 15:16:07 +00:00
}
2011-08-27 22:04:48 +00:00
/**
* Build a locale batch from an array of files .
*
2014-10-22 09:58:00 +00:00
* @ param array $files
2011-10-29 11:40:09 +00:00
* Array of file objects to import .
2012-08-19 10:46:48 +00:00
* @ param array $options
* An array with options that can have the following elements :
* - 'langcode' : The language code . Optional , defaults to NULL , which means
* that the language will be detected from the name of the files .
* - 'overwrite_options' : Overwrite options array as defined in
* Drupal\locale\PoDatabaseWriter . Optional , defaults to an empty array .
* - 'customized' : Flag indicating whether the strings imported from $file
* are customized translations or come from a community source . Use
* LOCALE_CUSTOMIZED or LOCALE_NOT_CUSTOMIZED . Optional , defaults to
* LOCALE_NOT_CUSTOMIZED .
* - 'finish_feedback' : Whether or not to give feedback to the user when the
* batch is finished . Optional , defaults to TRUE .
2011-08-27 22:04:48 +00:00
*
2014-10-22 09:58:00 +00:00
* @ return array | bool
2011-10-29 11:40:09 +00:00
* A batch structure or FALSE if $files was empty .
2011-08-27 22:04:48 +00:00
*/
2014-10-22 09:58:00 +00:00
function locale_translate_batch_build ( array $files , array $options ) {
2017-03-04 01:20:24 +00:00
$options += [
'overwrite_options' => [],
2012-08-19 10:46:48 +00:00
'customized' => LOCALE_NOT_CUSTOMIZED ,
'finish_feedback' => TRUE ,
2017-03-04 01:20:24 +00:00
];
2011-08-27 22:04:48 +00:00
if ( count ( $files )) {
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
$batch_builder = ( new BatchBuilder ())
Issue #2347783 by kim.pepper, andypost, almaudoh, gumanist, aleevas, rodrigoaguilera, Berdir, saurabh-2k17, Spokje, dhirendra.mishra, alexpott, paulocs, izus, Wim Leers, KapilV, naveenvalecha, anmolgoyal74, subson, yo30, harsha012, mrinalini9, daffie, voleger, dww, fietserwin, tim.plunkett, joachim, larowlan: Deprecate drupal_get_path() and drupal_get_filename() and replace with ExtensionList::getPath() and ExtensionList::getPathname()
2021-07-15 10:20:33 +00:00
-> setFile ( \Drupal :: service ( 'extension.list.module' ) -> getPath ( 'locale' ) . '/locale.bulk.inc' )
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
-> setTitle ( t ( 'Importing interface translations' ))
-> setErrorMessage ( t ( 'Error importing interface translations' ));
2011-08-27 22:04:48 +00:00
foreach ( $files as $file ) {
2011-10-29 11:40:09 +00:00
// We call locale_translate_batch_import for every batch operation.
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
$batch_builder -> addOperation ( 'locale_translate_batch_import' , [ $file , $options ]);
2011-08-27 22:04:48 +00:00
}
2012-12-07 18:17:37 +00:00
// Save the translation status of all files.
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
$batch_builder -> addOperation ( 'locale_translate_batch_import_save' , []);
2012-12-07 18:17:37 +00:00
2013-04-23 07:19:41 +00:00
// Add a final step to refresh JavaScript and configuration strings.
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
$batch_builder -> addOperation ( 'locale_translate_batch_refresh' , []);
2012-08-19 10:46:48 +00:00
if ( $options [ 'finish_feedback' ]) {
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
$batch_builder -> setFinishCallback ( 'locale_translate_batch_finished' );
2011-08-27 22:04:48 +00:00
}
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
return $batch_builder -> toArray ();
2011-08-27 22:04:48 +00:00
}
return FALSE ;
}
/**
2015-02-13 19:51:15 +00:00
* Implements callback_batch_operation () .
*
* Perform interface translation import .
2011-08-27 22:04:48 +00:00
*
2012-12-07 18:17:37 +00:00
* @ param object $file
* A file object of the gettext file to be imported . The file object must
2014-07-21 10:52:00 +00:00
* contain a language parameter ( other than
* LanguageInterface :: LANGCODE_NOT_SPECIFIED ) . This is used as the language of
* the import .
2012-08-19 10:46:48 +00:00
* @ param array $options
* An array with options that can have the following elements :
2012-12-07 18:17:37 +00:00
* - 'langcode' : The language code .
2012-08-19 10:46:48 +00:00
* - 'overwrite_options' : Overwrite options array as defined in
* Drupal\locale\PoDatabaseWriter . Optional , defaults to an empty array .
* - 'customized' : Flag indicating whether the strings imported from $file
* are customized translations or come from a community source . Use
* LOCALE_CUSTOMIZED or LOCALE_NOT_CUSTOMIZED . Optional , defaults to
* LOCALE_NOT_CUSTOMIZED .
2012-12-17 21:45:18 +00:00
* - 'message' : Alternative message to display during import . Note , this must
* be sanitized text .
2017-03-18 23:33:40 +00:00
* @ param array | \ArrayAccess $context
2011-08-27 22:04:48 +00:00
* Contains a list of files imported .
*/
2016-03-04 00:44:13 +00:00
function locale_translate_batch_import ( $file , array $options , & $context ) {
2012-08-19 10:46:48 +00:00
// Merge the default values in the $options array.
2017-03-04 01:20:24 +00:00
$options += [
'overwrite_options' => [],
2012-08-19 10:46:48 +00:00
'customized' => LOCALE_NOT_CUSTOMIZED ,
2017-03-04 01:20:24 +00:00
];
2012-12-07 18:17:37 +00:00
2014-06-10 16:52:58 +00:00
if ( isset ( $file -> langcode ) && $file -> langcode != LanguageInterface :: LANGCODE_NOT_SPECIFIED ) {
2012-12-07 18:17:37 +00:00
2012-07-26 22:07:25 +00:00
try {
2012-08-19 10:46:48 +00:00
if ( empty ( $context [ 'sandbox' ])) {
2017-03-04 01:20:24 +00:00
$context [ 'sandbox' ][ 'parse_state' ] = [
2017-11-14 15:53:29 +00:00
'filesize' => filesize ( \Drupal :: service ( 'file_system' ) -> realpath ( $file -> uri )),
2012-08-19 10:46:48 +00:00
'chunk_size' => 200 ,
'seek' => 0 ,
2017-03-04 01:20:24 +00:00
];
2012-08-19 10:46:48 +00:00
}
// Update the seek and the number of items in the $options array().
$options [ 'seek' ] = $context [ 'sandbox' ][ 'parse_state' ][ 'seek' ];
$options [ 'items' ] = $context [ 'sandbox' ][ 'parse_state' ][ 'chunk_size' ];
2016-03-14 00:22:44 +00:00
$report = Gettext :: fileToDatabase ( $file , $options );
2012-08-19 10:46:48 +00:00
// If not yet finished with reading, mark progress based on size and
// position.
if ( $report [ 'seek' ] < filesize ( $file -> uri )) {
2012-12-07 18:17:37 +00:00
2012-08-19 10:46:48 +00:00
$context [ 'sandbox' ][ 'parse_state' ][ 'seek' ] = $report [ 'seek' ];
// Maximize the progress bar at 95% before completion, the batch API
// could trigger the end of the operation before file reading is done,
// because of floating point inaccuracies. See
2015-05-18 21:08:10 +00:00
// https://www.drupal.org/node/1089472.
2012-08-19 10:46:48 +00:00
$context [ 'finished' ] = min ( 0.95 , $report [ 'seek' ] / filesize ( $file -> uri ));
2012-12-07 18:17:37 +00:00
if ( isset ( $options [ 'message' ])) {
2017-03-04 01:20:24 +00:00
$context [ 'message' ] = t ( '@message (@percent%).' , [ '@message' => $options [ 'message' ], '@percent' => ( int ) ( $context [ 'finished' ] * 100 )]);
2012-12-07 18:17:37 +00:00
}
else {
2017-03-04 01:20:24 +00:00
$context [ 'message' ] = t ( 'Importing translation file: %filename (@percent%).' , [ '%filename' => $file -> filename , '@percent' => ( int ) ( $context [ 'finished' ] * 100 )]);
2012-12-07 18:17:37 +00:00
}
2012-08-19 10:46:48 +00:00
}
else {
// We are finished here.
$context [ 'finished' ] = 1 ;
2012-12-07 18:17:37 +00:00
// Store the file data for processing by the next batch operation.
2012-08-19 10:46:48 +00:00
$file -> timestamp = filemtime ( $file -> uri );
2012-12-07 18:17:37 +00:00
$context [ 'results' ][ 'files' ][ $file -> uri ] = $file ;
$context [ 'results' ][ 'languages' ][ $file -> uri ] = $file -> langcode ;
2012-08-19 10:46:48 +00:00
}
2012-12-07 18:17:37 +00:00
// Add the reported values to the statistics for this file.
// Each import iteration reports statistics in an array. The results of
// each iteration are added and merged here and stored per file.
if ( ! isset ( $context [ 'results' ][ 'stats' ]) || ! isset ( $context [ 'results' ][ 'stats' ][ $file -> uri ])) {
2017-03-04 01:20:24 +00:00
$context [ 'results' ][ 'stats' ][ $file -> uri ] = [];
2012-08-19 10:46:48 +00:00
}
foreach ( $report as $key => $value ) {
2012-12-07 18:17:37 +00:00
if ( is_numeric ( $report [ $key ])) {
if ( ! isset ( $context [ 'results' ][ 'stats' ][ $file -> uri ][ $key ])) {
$context [ 'results' ][ 'stats' ][ $file -> uri ][ $key ] = 0 ;
}
$context [ 'results' ][ 'stats' ][ $file -> uri ][ $key ] += $report [ $key ];
2012-10-23 10:25:45 +00:00
}
elseif ( is_array ( $value )) {
2017-03-04 01:20:24 +00:00
$context [ 'results' ][ 'stats' ][ $file -> uri ] += [ $key => []];
2012-12-07 18:17:37 +00:00
$context [ 'results' ][ 'stats' ][ $file -> uri ][ $key ] = array_merge ( $context [ 'results' ][ 'stats' ][ $file -> uri ][ $key ], $value );
2012-08-19 10:46:48 +00:00
}
}
2012-08-18 10:36:45 +00:00
}
catch ( Exception $exception ) {
2012-12-07 18:17:37 +00:00
// Import failed. Store the data of the failing file.
$context [ 'results' ][ 'failed_files' ][] = $file ;
2017-03-04 01:20:24 +00:00
\Drupal :: logger ( 'locale' ) -> notice ( 'Unable to import translations file: @file' , [ '@file' => $file -> uri ]);
2012-12-07 18:17:37 +00:00
}
}
}
/**
2015-02-13 19:51:15 +00:00
* Implements callback_batch_operation () .
*
* Save data of imported files .
2012-12-07 18:17:37 +00:00
*
2017-03-18 23:33:40 +00:00
* @ param array | \ArrayAccess $context
2012-12-07 18:17:37 +00:00
* Contains a list of imported files .
*/
2016-03-04 00:44:13 +00:00
function locale_translate_batch_import_save ( $context ) {
2012-12-07 18:17:37 +00:00
if ( isset ( $context [ 'results' ][ 'files' ])) {
2022-07-04 14:26:28 +00:00
$request_time = \Drupal :: time () -> getRequestTime ();
2012-12-07 18:17:37 +00:00
foreach ( $context [ 'results' ][ 'files' ] as $file ) {
// Update the file history if both project and version are known. This
// table is used by the automated translation update function which tracks
// translation status of module and themes in the system. Other
// translation files are not tracked and are therefore not stored in this
// table.
if ( $file -> project && $file -> version ) {
2022-07-04 14:26:28 +00:00
$file -> last_checked = $request_time ;
2012-12-07 18:17:37 +00:00
locale_translation_update_file_history ( $file );
}
2012-06-16 15:16:07 +00:00
}
2012-12-17 21:45:18 +00:00
$context [ 'message' ] = t ( 'Translations imported.' );
2011-08-27 22:04:48 +00:00
}
}
2013-04-23 07:19:41 +00:00
/**
2015-02-13 19:51:15 +00:00
* Implements callback_batch_operation () .
*
2015-04-02 10:59:11 +00:00
* Refreshes translations after importing strings .
2013-04-23 07:19:41 +00:00
*
2017-03-18 23:33:40 +00:00
* @ param array | \ArrayAccess $context
2013-04-23 07:19:41 +00:00
* Contains a list of strings updated and information about the progress .
*/
2016-03-04 00:44:13 +00:00
function locale_translate_batch_refresh ( & $context ) {
2013-04-23 07:19:41 +00:00
if ( ! isset ( $context [ 'sandbox' ][ 'refresh' ])) {
2017-03-04 01:20:24 +00:00
$strings = $langcodes = [];
2013-04-23 07:19:41 +00:00
if ( isset ( $context [ 'results' ][ 'stats' ])) {
// Get list of unique string identifiers and language codes updated.
$langcodes = array_unique ( array_values ( $context [ 'results' ][ 'languages' ]));
Issue #2002650 by mrsinguyen, chertzog, legolasbo, Erik Erskine, rhm50, sandergo90, grisendo, targoo, janstoeckler, maximpodorov, beowulf1416: Improve maintainability by removing unused local variables.
2013-10-02 13:52:21 +00:00
foreach ( $context [ 'results' ][ 'stats' ] as $report ) {
2022-02-07 11:26:28 +00:00
$strings [] = $report [ 'strings' ];
2013-04-23 07:19:41 +00:00
}
2023-02-17 12:16:21 +00:00
$strings = array_merge ( ... $strings );
2013-04-23 07:19:41 +00:00
}
if ( $strings ) {
// Initialize multi-step string refresh.
2014-08-04 22:21:49 +00:00
$context [ 'message' ] = t ( 'Updating translations for JavaScript and default configuration.' );
2013-04-23 07:19:41 +00:00
$context [ 'sandbox' ][ 'refresh' ][ 'strings' ] = array_unique ( $strings );
$context [ 'sandbox' ][ 'refresh' ][ 'languages' ] = $langcodes ;
2017-03-04 01:20:24 +00:00
$context [ 'sandbox' ][ 'refresh' ][ 'names' ] = [];
2013-04-23 07:19:41 +00:00
$context [ 'results' ][ 'stats' ][ 'config' ] = 0 ;
$context [ 'sandbox' ][ 'refresh' ][ 'count' ] = count ( $strings );
// We will update strings on later steps.
2014-08-04 22:21:49 +00:00
$context [ 'finished' ] = 0 ;
2013-04-23 07:19:41 +00:00
}
else {
$context [ 'finished' ] = 1 ;
}
}
elseif ( $name = array_shift ( $context [ 'sandbox' ][ 'refresh' ][ 'names' ])) {
// Refresh all languages for one object at a time.
2024-04-29 07:35:43 +00:00
$count = \Drupal :: service ( 'locale.config_manager' )
-> updateConfigTranslations ([ $name ], $context [ 'sandbox' ][ 'refresh' ][ 'languages' ]);
2013-04-23 07:19:41 +00:00
$context [ 'results' ][ 'stats' ][ 'config' ] += $count ;
2014-08-04 22:21:49 +00:00
// Inherit finished information from the "parent" string lookup step so
// visual display of status will make sense.
$context [ 'finished' ] = $context [ 'sandbox' ][ 'refresh' ][ 'names_finished' ];
2017-03-04 01:20:24 +00:00
$context [ 'message' ] = t ( 'Updating default configuration (@percent%).' , [ '@percent' => ( int ) ( $context [ 'finished' ] * 100 )]);
2013-04-23 07:19:41 +00:00
}
elseif ( ! empty ( $context [ 'sandbox' ][ 'refresh' ][ 'strings' ])) {
// Not perfect but will give some indication of progress.
$context [ 'finished' ] = 1 - count ( $context [ 'sandbox' ][ 'refresh' ][ 'strings' ]) / $context [ 'sandbox' ][ 'refresh' ][ 'count' ];
// Pending strings, refresh 100 at a time, get next pack.
$next = array_slice ( $context [ 'sandbox' ][ 'refresh' ][ 'strings' ], 0 , 100 );
array_splice ( $context [ 'sandbox' ][ 'refresh' ][ 'strings' ], 0 , count ( $next ));
// Clear cache and force refresh of JavaScript translations.
_locale_refresh_translations ( $context [ 'sandbox' ][ 'refresh' ][ 'languages' ], $next );
// Check whether we need to refresh configuration objects.
2024-04-29 07:35:43 +00:00
if ( $names = \Drupal :: service ( 'locale.config_manager' )
-> getStringNames ( $next )) {
2014-08-04 22:21:49 +00:00
$context [ 'sandbox' ][ 'refresh' ][ 'names_finished' ] = $context [ 'finished' ];
2013-04-23 07:19:41 +00:00
$context [ 'sandbox' ][ 'refresh' ][ 'names' ] = $names ;
}
}
else {
2014-08-04 22:21:49 +00:00
$context [ 'message' ] = t ( 'Updated default configuration.' );
2013-04-23 07:19:41 +00:00
$context [ 'finished' ] = 1 ;
}
}
2011-08-27 22:04:48 +00:00
/**
2015-02-13 19:51:15 +00:00
* Implements callback_batch_finished () .
*
2011-08-27 22:04:48 +00:00
* Finished callback of system page locale import batch .
2014-10-22 09:58:00 +00:00
*
* @ param bool $success
* TRUE if batch successfully completed .
* @ param array $results
* Batch results .
2011-08-27 22:04:48 +00:00
*/
2014-10-22 09:58:00 +00:00
function locale_translate_batch_finished ( $success , array $results ) {
2014-06-26 18:55:12 +00:00
$logger = \Drupal :: logger ( 'locale' );
2011-08-27 22:04:48 +00:00
if ( $success ) {
2020-08-28 09:40:43 +00:00
$additions = $updates = $deletes = $skips = 0 ;
2012-12-07 18:17:37 +00:00
if ( isset ( $results [ 'failed_files' ])) {
2014-08-15 22:58:36 +00:00
if ( \Drupal :: moduleHandler () -> moduleExists ( 'dblog' ) && \Drupal :: currentUser () -> hasPermission ( 'access site reports' )) {
2019-04-16 05:38:27 +00:00
$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 ()]);
2013-04-23 07:19:41 +00:00
}
else {
2015-01-10 13:56:47 +00:00
$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.' );
2013-04-23 07:19:41 +00:00
}
2018-05-01 09:15:07 +00:00
\Drupal :: messenger () -> addError ( $message );
2012-07-26 22:07:25 +00:00
}
2012-12-07 18:17:37 +00:00
if ( isset ( $results [ 'files' ])) {
2017-03-04 01:20:24 +00:00
$skipped_files = [];
2012-12-07 18:17:37 +00:00
// 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 ) {
2020-02-04 16:24:45 +00:00
if ( $filepath === 'config' ) {
// Ignore the config entry. It is processed in
// locale_config_batch_finished() below.
continue ;
}
2012-12-07 18:17:37 +00:00
$additions += $report [ 'additions' ];
$updates += $report [ 'updates' ];
$deletes += $report [ 'deletes' ];
$skips += $report [ 'skips' ];
if ( $report [ 'skips' ] > 0 ) {
$skipped_files [] = $filepath ;
}
}
2012-07-26 22:07:25 +00:00
}
2018-05-01 09:15:07 +00:00
\Drupal :: messenger () -> addStatus ( \Drupal :: translation () -> formatPlural ( count ( $results [ 'files' ]),
2012-12-07 18:17:37 +00:00
'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.' ,
2017-03-04 01:20:24 +00:00
[ '%number' => $additions , '%update' => $updates , '%delete' => $deletes ]
2012-12-07 18:17:37 +00:00
));
2017-03-04 01:20:24 +00:00
$logger -> notice ( 'Translations imported: %number added, %update updated, %delete removed.' , [ '%number' => $additions , '%update' => $updates , '%delete' => $deletes ]);
2012-12-07 18:17:37 +00:00
if ( $skips ) {
2014-08-15 22:58:36 +00:00
if ( \Drupal :: moduleHandler () -> moduleExists ( 'dblog' ) && \Drupal :: currentUser () -> hasPermission ( 'access site reports' )) {
2019-04-16 05:38:27 +00:00
$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 ()]);
2012-12-07 18:17:37 +00:00
}
else {
2015-01-10 13:56:47 +00:00
$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.' );
2012-12-07 18:17:37 +00:00
}
2018-05-01 09:15:07 +00:00
\Drupal :: messenger () -> addWarning ( $message );
2017-03-04 01:20:24 +00:00
$logger -> warning ( '@count disallowed HTML string(s) in files: @files.' , [ '@count' => $skips , '@files' => implode ( ',' , $skipped_files )]);
2012-07-26 22:07:25 +00:00
}
2012-10-23 10:25:45 +00:00
}
2011-08-27 22:04:48 +00:00
}
2013-04-23 07:19:41 +00:00
// Add messages for configuration too.
if ( isset ( $results [ 'stats' ][ 'config' ])) {
locale_config_batch_finished ( $success , $results );
}
2011-08-27 22:04:48 +00:00
}
2012-06-16 15:16:07 +00:00
/**
* Creates a file object and populates the timestamp property .
*
2014-10-22 09:58:00 +00:00
* @ param string $filepath
2012-06-16 15:16:07 +00:00
* The filepath of a file to import .
*
2014-10-22 09:58:00 +00:00
* @ return object
2012-06-16 15:16:07 +00:00
* An object representing the file .
*/
function locale_translate_file_create ( $filepath ) {
$file = new stdClass ();
2019-03-07 09:12:01 +00:00
$file -> filename = \Drupal :: service ( 'file_system' ) -> basename ( $filepath );
2012-06-16 15:16:07 +00:00
$file -> uri = $filepath ;
2012-09-17 23:16:44 +00:00
$file -> timestamp = filemtime ( $file -> uri );
2012-06-16 15:16:07 +00:00
return $file ;
}
/**
2013-04-23 07:19:41 +00:00
* Generates file properties from filename and options .
2012-06-16 15:16:07 +00:00
*
2012-12-07 18:17:37 +00:00
* An attempt is made to determine the translation language , project name and
* project version from the file name . Supported file name patterns are :
* { project } - { version } . { langcode } . po , { prefix } . { langcode } . po or { langcode } . po .
* Alternatively the translation language can be set using the $options .
2012-06-16 15:16:07 +00:00
*
2012-12-07 18:17:37 +00:00
* @ param object $file
* A file object of the gettext file to be imported .
* @ param array $options
* An array with options :
* - 'langcode' : The language code . Overrides the file language .
2012-06-16 15:16:07 +00:00
*
2012-12-07 18:17:37 +00:00
* @ return object
* Modified file object .
2012-06-16 15:16:07 +00:00
*/
2017-03-04 01:20:24 +00:00
function locale_translate_file_attach_properties ( $file , array $options = []) {
2013-06-15 08:46:11 +00:00
// If $file is a file entity, convert it to a stdClass.
if ( $file instanceof FileInterface ) {
2017-03-04 01:20:24 +00:00
$file = ( object ) [
2013-06-15 08:46:11 +00:00
'filename' => $file -> getFilename (),
'uri' => $file -> getFileUri (),
2017-03-04 01:20:24 +00:00
];
2013-06-15 08:46:11 +00:00
}
2013-09-12 14:01:59 +00:00
// Extract project, version and language code from the file name. Supported:
2012-12-07 18:17:37 +00:00
// {project}-{version}.{langcode}.po, {prefix}.{langcode}.po or {langcode}.po
preg_match ( ' !
2015-04-02 10:59:11 +00:00
( # project OR project and version OR empty (group 1)
2012-12-07 18:17:37 +00:00
([ a - z_ ] + ) # project name (group 2)
\ . # .
| # OR
([ a - z_ ] + ) # project name (group 3)
\ - # -
([ 0 - 9 a - z\ . \ - \ + ] + ) # version (group 4)
\ . # .
| # OR
) # (empty)
([ ^ \ ./ ] + ) # language code (group 5)
\ . # .
po # po extension
$ ! x ' , $file -> filename , $matches );
if ( isset ( $matches [ 5 ])) {
$file -> project = $matches [ 2 ] . $matches [ 3 ];
$file -> version = $matches [ 4 ];
2021-11-15 02:19:43 +00:00
$file -> langcode = $options [ 'langcode' ] ? ? $matches [ 5 ];
2012-06-16 15:16:07 +00:00
}
else {
2014-06-10 16:52:58 +00:00
$file -> langcode = LanguageInterface :: LANGCODE_NOT_SPECIFIED ;
2012-06-16 15:16:07 +00:00
}
2012-12-07 18:17:37 +00:00
return $file ;
2012-06-16 15:16:07 +00:00
}
/**
2012-12-07 18:17:37 +00:00
* Deletes interface translation files and translation history records .
2012-06-16 15:16:07 +00:00
*
2012-12-07 18:17:37 +00:00
* @ param array $projects
2014-10-22 09:58:00 +00:00
* ( optional ) Project names from which to delete the translation files and
* history . Defaults to all projects .
2012-12-07 18:17:37 +00:00
* @ param array $langcodes
2014-10-22 09:58:00 +00:00
* ( optional ) Language codes from which to delete the translation files and
* history . Defaults to all languages .
2012-12-07 18:17:37 +00:00
*
2014-07-21 10:52:00 +00:00
* @ return bool
2013-12-03 15:54:20 +00:00
* TRUE if files are removed successfully . FALSE if one or more files could
2012-12-07 18:17:37 +00:00
* not be deleted .
2012-06-16 15:16:07 +00:00
*/
2017-03-04 01:20:24 +00:00
function locale_translate_delete_translation_files ( array $projects = [], array $langcodes = []) {
2012-12-07 18:17:37 +00:00
$fail = FALSE ;
locale_translation_file_history_delete ( $projects , $langcodes );
// Delete all translation files from the translations directory.
if ( $files = locale_translate_get_interface_translation_files ( $projects , $langcodes )) {
2012-06-16 15:16:07 +00:00
foreach ( $files as $file ) {
Issue #2244513 by kim.pepper, phenaproxima, 20th, andrei.dincu, beejeebus, Berdir, alexpott, jibran, andypost, larowlan, Chadwick Wood, acbramley, Wim Leers, sun, xjm, YesCT, chx, tim.plunkett: Move the unmanaged file APIs to the file_system service (file.inc)
2019-02-23 22:35:15 +00:00
try {
\Drupal :: service ( 'file_system' ) -> delete ( $file -> uri );
}
catch ( FileException $e ) {
2012-12-07 18:17:37 +00:00
$fail = TRUE ;
2012-06-16 15:16:07 +00:00
}
}
}
2012-12-07 18:17:37 +00:00
return ! $fail ;
2012-06-16 15:16:07 +00:00
}
2013-04-23 07:19:41 +00:00
/**
* Builds a locale batch to refresh configuration .
*
* @ param array $options
* An array with options that can have the following elements :
* - 'finish_feedback' : ( optional ) Whether or not to give feedback to the user
* when the batch is finished . Defaults to TRUE .
* @ param array $langcodes
* ( optional ) Array of language codes . Defaults to all translatable languages .
* @ param array $components
* ( optional ) Array of component lists indexed by type . If not present or it
* is an empty array , it will update all components .
Issue #2806009 by alexpott, JvE, Berdir, Dmitriy.trt, jhodgdon, lokapujya, VladimirAus, Gábor Hojtsy, Jose Reyero, Anybody, kristiaanvandeneynde, Sutharsan, casey, smustgrave, nod_: Installing a module causes translations to be overwritten
2023-03-17 17:35:34 +00:00
* @ param bool $update_default_config_langcodes
* Determines whether default configuration langcodes should be updated . This
* Should only happen during site and extension install .
2013-04-23 07:19:41 +00:00
*
* @ return array
* The batch definition .
*/
Issue #2806009 by alexpott, JvE, Berdir, Dmitriy.trt, jhodgdon, lokapujya, VladimirAus, Gábor Hojtsy, Jose Reyero, Anybody, kristiaanvandeneynde, Sutharsan, casey, smustgrave, nod_: Installing a module causes translations to be overwritten
2023-03-17 17:35:34 +00:00
function locale_config_batch_update_components ( array $options , array $langcodes = [], array $components = [], bool $update_default_config_langcodes = FALSE ) {
2015-03-26 12:05:36 +00:00
$langcodes = $langcodes ? $langcodes : array_keys ( \Drupal :: languageManager () -> getLanguages ());
2024-04-29 07:35:43 +00:00
if ( $langcodes && $names = \Drupal :: service ( 'locale.config_manager' ) -> getComponentNames ( $components )) {
Issue #2806009 by alexpott, JvE, Berdir, Dmitriy.trt, jhodgdon, lokapujya, VladimirAus, Gábor Hojtsy, Jose Reyero, Anybody, kristiaanvandeneynde, Sutharsan, casey, smustgrave, nod_: Installing a module causes translations to be overwritten
2023-03-17 17:35:34 +00:00
// If the component list is empty we need to ensure that all configuration
// in the default collection is using the site's default langcode.
return locale_config_batch_build ( $names , $langcodes , $options , $update_default_config_langcodes );
2013-04-23 07:19:41 +00:00
}
}
/**
* Creates a locale batch to refresh specific configuration .
*
* @ param array $names
* List of configuration object names ( which are strings ) to update .
* @ param array $langcodes
* List of language codes to refresh .
* @ param array $options
* ( optional ) An array with options that can have the following elements :
* - 'finish_feedback' : Whether or not to give feedback to the user when the
* batch is finished . Defaults to TRUE .
Issue #2806009 by alexpott, JvE, Berdir, Dmitriy.trt, jhodgdon, lokapujya, VladimirAus, Gábor Hojtsy, Jose Reyero, Anybody, kristiaanvandeneynde, Sutharsan, casey, smustgrave, nod_: Installing a module causes translations to be overwritten
2023-03-17 17:35:34 +00:00
* @ param bool $update_default_config_langcodes
* Determines whether default configuration langcodes should be updated . This
* Should only happen during site and extension install .
2013-04-23 07:19:41 +00:00
*
* @ return array
* The batch definition .
*
* @ see locale_config_batch_refresh_name ()
*/
Issue #2806009 by alexpott, JvE, Berdir, Dmitriy.trt, jhodgdon, lokapujya, VladimirAus, Gábor Hojtsy, Jose Reyero, Anybody, kristiaanvandeneynde, Sutharsan, casey, smustgrave, nod_: Installing a module causes translations to be overwritten
2023-03-17 17:35:34 +00:00
function locale_config_batch_build ( array $names , array $langcodes , array $options = [], bool $update_default_config_langcodes = FALSE ) {
2017-03-04 01:20:24 +00:00
$options += [ 'finish_feedback' => TRUE ];
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
$batch_builder = ( new BatchBuilder ())
Issue #2347783 by kim.pepper, andypost, almaudoh, gumanist, aleevas, rodrigoaguilera, Berdir, saurabh-2k17, Spokje, dhirendra.mishra, alexpott, paulocs, izus, Wim Leers, KapilV, naveenvalecha, anmolgoyal74, subson, yo30, harsha012, mrinalini9, daffie, voleger, dww, fietserwin, tim.plunkett, joachim, larowlan: Deprecate drupal_get_path() and drupal_get_filename() and replace with ExtensionList::getPath() and ExtensionList::getPathname()
2021-07-15 10:20:33 +00:00
-> setFile ( \Drupal :: service ( 'extension.list.module' ) -> getPath ( 'locale' ) . '/locale.bulk.inc' )
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
-> setTitle ( t ( 'Updating configuration translations' ))
-> setInitMessage ( t ( 'Starting configuration update' ))
-> setErrorMessage ( t ( 'Error updating configuration translations' ));
Issue #2806009 by alexpott, JvE, Berdir, Dmitriy.trt, jhodgdon, lokapujya, VladimirAus, Gábor Hojtsy, Jose Reyero, Anybody, kristiaanvandeneynde, Sutharsan, casey, smustgrave, nod_: Installing a module causes translations to be overwritten
2023-03-17 17:35:34 +00:00
if ( $update_default_config_langcodes && \Drupal :: languageManager () -> getDefaultLanguage () -> getId () !== 'en' ) {
$batch_builder -> addOperation ( 'locale_config_batch_set_config_langcodes' );
}
2024-03-02 12:02:21 +00:00
// Chunking the array of names into batches of 20 for better performance.
$name_chunks = array_chunk ( $names , 20 );
foreach ( $name_chunks as $chunk ) {
2014-07-21 10:52:00 +00:00
// During installation the caching of configuration objects is disabled so
// it is very expensive to initialize the \Drupal::config() object on each
// request. We batch a small number of configuration object upgrades
// together to improve the overall performance of the process.
2024-03-02 12:02:21 +00:00
$batch_builder -> addOperation ( 'locale_config_batch_refresh_name' , [ $chunk , $langcodes ]);
2013-04-23 07:19:41 +00:00
}
2024-03-02 12:02:21 +00:00
2013-04-23 07:19:41 +00:00
if ( ! empty ( $options [ 'finish_feedback' ])) {
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
$batch_builder -> setFinishCallback ( 'locale_config_batch_finished' );
2013-04-23 07:19:41 +00:00
}
Issue #2875279 by Spokje, John Cook, jungle, voleger, mradcliffe, mrinalini9, jpatel657, quietone, jonathanshaw, alexpott, joachim, rajeshwari10, RajeevK, Yogesh Pawar, James.Shee, lcngeo, borisson_, time2buzzthetower, ccasals, kavo: Update core modules to use the new batch builder
2021-06-28 12:30:58 +00:00
return $batch_builder -> toArray ();
2013-04-23 07:19:41 +00:00
}
Issue #2806009 by alexpott, JvE, Berdir, Dmitriy.trt, jhodgdon, lokapujya, VladimirAus, Gábor Hojtsy, Jose Reyero, Anybody, kristiaanvandeneynde, Sutharsan, casey, smustgrave, nod_: Installing a module causes translations to be overwritten
2023-03-17 17:35:34 +00:00
/**
* Implements callback_batch_operation () .
*
* Updates default configuration when new modules or themes are installed .
*
* @ param array | \ArrayAccess $context
* The batch context .
*/
function locale_config_batch_set_config_langcodes ( & $context ) {
2024-04-29 07:35:43 +00:00
\Drupal :: service ( 'locale.config_manager' ) -> updateDefaultConfigLangcodes ();
Issue #2806009 by alexpott, JvE, Berdir, Dmitriy.trt, jhodgdon, lokapujya, VladimirAus, Gábor Hojtsy, Jose Reyero, Anybody, kristiaanvandeneynde, Sutharsan, casey, smustgrave, nod_: Installing a module causes translations to be overwritten
2023-03-17 17:35:34 +00:00
$context [ 'finished' ] = 1 ;
$context [ 'message' ] = t ( 'Updated default configuration to %langcode' , [ '%langcode' => \Drupal :: languageManager () -> getDefaultLanguage () -> getId ()]);
}
2013-04-23 07:19:41 +00:00
/**
2015-02-13 19:51:15 +00:00
* Implements callback_batch_operation () .
*
* Performs configuration translation refresh .
2013-04-23 07:19:41 +00:00
*
2014-10-22 09:58:00 +00:00
* @ param array $names
* An array of names of configuration objects to update .
2013-04-23 07:19:41 +00:00
* @ param array $langcodes
* ( optional ) Array of language codes to update . Defaults to all languages .
2017-03-18 23:33:40 +00:00
* @ param array | \ArrayAccess $context
2013-04-23 07:19:41 +00:00
* Contains a list of files imported .
*
* @ see locale_config_batch_build ()
*/
2016-03-04 00:44:13 +00:00
function locale_config_batch_refresh_name ( array $names , array $langcodes , & $context ) {
2024-01-10 03:32:11 +00:00
if ( ! isset ( $context [ 'results' ][ 'stats' ][ 'config' ])) {
$context [ 'results' ][ 'stats' ][ 'config' ] = 0 ;
2013-04-23 07:19:41 +00:00
}
2024-04-29 07:35:43 +00:00
$context [ 'results' ][ 'stats' ][ 'config' ] += \Drupal :: service ( 'locale.config_manager' )
-> updateConfigTranslations ( $names , $langcodes );
2013-06-28 17:46:47 +00:00
foreach ( $names as $name ) {
2024-01-10 03:32:11 +00:00
$context [ 'results' ][ 'names' ][] = $name ;
2013-06-28 17:46:47 +00:00
}
2024-01-10 03:32:11 +00:00
$context [ 'results' ][ 'langcodes' ] = $langcodes ;
2013-04-23 07:19:41 +00:00
$context [ 'finished' ] = 1 ;
}
/**
2015-02-13 19:51:15 +00:00
* Implements callback_batch_finished () .
*
2013-04-23 07:19:41 +00:00
* Finishes callback of system page locale import batch .
*
* @ param bool $success
* Information about the success of the batch import .
* @ param array $results
* Information about the results of the batch import .
2014-07-21 10:52:00 +00:00
*
* @ see locale_config_batch_build ()
2013-04-23 07:19:41 +00:00
*/
function locale_config_batch_finished ( $success , array $results ) {
if ( $success ) {
2021-11-15 02:19:43 +00:00
$configuration = $results [ 'stats' ][ 'config' ] ? ? 0 ;
2013-04-23 07:19:41 +00:00
if ( $configuration ) {
2018-05-01 09:15:07 +00:00
\Drupal :: messenger () -> addStatus ( t ( 'The configuration was successfully updated. There are %number configuration objects updated.' , [ '%number' => $configuration ]));
2017-03-04 01:20:24 +00:00
\Drupal :: logger ( 'locale' ) -> notice ( 'The configuration was successfully updated. %number configuration objects updated.' , [ '%number' => $configuration ]);
2013-04-23 07:19:41 +00:00
}
else {
2018-05-01 09:15:07 +00:00
\Drupal :: messenger () -> addStatus ( t ( 'No configuration objects have been updated.' ));
2014-06-26 18:55:12 +00:00
\Drupal :: logger ( 'locale' ) -> warning ( 'No configuration objects have been updated.' );
2013-04-23 07:19:41 +00:00
}
}
}