2012-12-07 18:17:37 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* The API for download and import of translations from remote and local sources.
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
2012-12-07 18:17:37 +00:00
|
|
|
/**
|
|
|
|
* Load the common translation API.
|
|
|
|
*/
|
|
|
|
// @todo Combine functions differently in files to avoid unnecessary includes.
|
2015-05-18 21:08:10 +00:00
|
|
|
// Follow-up issue: https://www.drupal.org/node/1834298.
|
2013-05-09 09:25:10 +00:00
|
|
|
require_once __DIR__ . '/locale.translation.inc';
|
2012-12-07 18:17:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds a batch to check, download and import project translations.
|
|
|
|
*
|
|
|
|
* @param array $projects
|
|
|
|
* Array of project names for which to update the translations. Defaults to
|
|
|
|
* all translatable projects.
|
|
|
|
* @param array $langcodes
|
|
|
|
* Array of language codes. Defaults to all translatable languages.
|
|
|
|
* @param array $options
|
|
|
|
* Array of import options. See locale_translate_batch_import_files().
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* Batch definition array.
|
|
|
|
*/
|
2017-03-04 01:20:24 +00:00
|
|
|
function locale_translation_batch_update_build($projects = [], $langcodes = [], $options = []) {
|
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
(cherry picked from commit a9f20f76b29cfd7c8bb2315dc8ded75dc4f669f5)
2022-01-06 10:01:52 +00:00
|
|
|
\Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.compare');
|
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());
|
2013-06-27 11:25:01 +00:00
|
|
|
$status_options = $options;
|
|
|
|
$status_options['finish_feedback'] = FALSE;
|
2012-12-07 18:17:37 +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
|
|
|
$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.batch.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 translations'))
|
|
|
|
->setErrorMessage(t('Error importing translation files'))
|
|
|
|
->setFinishCallback('locale_translation_batch_fetch_finished');
|
2013-06-27 11:25:01 +00:00
|
|
|
// Check status of local and remote translation files.
|
|
|
|
$operations = _locale_translation_batch_status_operations($projects, $langcodes, $status_options);
|
|
|
|
// Download and import translations.
|
2012-12-07 18:17:37 +00:00
|
|
|
$operations = array_merge($operations, _locale_translation_fetch_operations($projects, $langcodes, $options));
|
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
|
|
|
array_walk($operations, function ($operation) use ($batch_builder) {
|
|
|
|
call_user_func_array([$batch_builder, 'addOperation'], $operation);
|
|
|
|
});
|
2012-12-07 18:17:37 +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();
|
2012-12-07 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds a batch to download and import project translations.
|
|
|
|
*
|
|
|
|
* @param array $projects
|
|
|
|
* Array of project names for which to check the state of translation files.
|
|
|
|
* Defaults to all translatable projects.
|
|
|
|
* @param array $langcodes
|
|
|
|
* Array of language codes. Defaults to all translatable languages.
|
|
|
|
* @param array $options
|
|
|
|
* Array of import options. See locale_translate_batch_import_files().
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* Batch definition array.
|
|
|
|
*/
|
2017-03-04 01:20:24 +00:00
|
|
|
function locale_translation_batch_fetch_build($projects = [], $langcodes = [], $options = []) {
|
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());
|
|
|
|
|
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())
|
|
|
|
->setTitle(t('Updating translations.'))
|
|
|
|
->setErrorMessage(t('Error importing translation files'))
|
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.batch.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
|
|
|
->setFinishCallback('locale_translation_batch_fetch_finished');
|
|
|
|
$operations = _locale_translation_fetch_operations($projects, $langcodes, $options);
|
|
|
|
array_walk($operations, function ($operation) use ($batch_builder) {
|
|
|
|
call_user_func_array([$batch_builder, 'addOperation'], $operation);
|
|
|
|
});
|
|
|
|
return $batch_builder->toArray();
|
2012-12-07 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to construct the batch operations to fetch translations.
|
|
|
|
*
|
|
|
|
* @param array $projects
|
|
|
|
* Array of project names for which to check the state of translation files.
|
|
|
|
* Defaults to all translatable projects.
|
|
|
|
* @param array $langcodes
|
|
|
|
* Array of language codes. Defaults to all translatable languages.
|
|
|
|
* @param array $options
|
|
|
|
* Array of import options.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* Array of batch operations.
|
|
|
|
*/
|
|
|
|
function _locale_translation_fetch_operations($projects, $langcodes, $options) {
|
2017-03-04 01:20:24 +00:00
|
|
|
$operations = [];
|
2012-12-07 18:17:37 +00:00
|
|
|
|
|
|
|
foreach ($projects as $project) {
|
|
|
|
foreach ($langcodes as $langcode) {
|
|
|
|
if (locale_translation_use_remote_source()) {
|
2017-03-04 01:20:24 +00:00
|
|
|
$operations[] = ['locale_translation_batch_fetch_download', [$project, $langcode]];
|
2012-12-07 18:17:37 +00:00
|
|
|
}
|
2017-03-04 01:20:24 +00:00
|
|
|
$operations[] = ['locale_translation_batch_fetch_import', [$project, $langcode, $options]];
|
2012-12-07 18:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $operations;
|
|
|
|
}
|