locale_translate_batch_import_files(array $options, $force = FALSE)
Prepare a batch to import all translations.
@todo Integrate with update status to identify projects needed and integrate l10n_update functionality to feed in translation files alike. See https://www.drupal.org/node/1191488.
array $options: An array with options that can have the following elements:
bool $force: (optional) Import all available files, even if they were imported before.
array|bool The batch structure, or FALSE if no files are used to build the batch.
function locale_translate_batch_import_files(array $options, $force = FALSE) {
$options += array(
'overwrite_options' => array(),
'customized' => LOCALE_NOT_CUSTOMIZED,
'finish_feedback' => TRUE,
);
if (!empty($options['langcode'])) {
$langcodes = array($options['langcode']);
}
else {
// If langcode was not provided, make sure to only import files for the
// languages we have added.
$langcodes = array_keys(\Drupal::languageManager()->getLanguages());
}
$files = locale_translate_get_interface_translation_files(array(), $langcodes);
if (!$force) {
$result = db_select('locale_file', 'lf')
->fields('lf', array('langcode', 'uri', 'timestamp'))
->condition('langcode', $langcodes)
->execute()
->fetchAllAssoc('uri');
foreach ($result as $uri => $info) {
if (isset($files[$uri]) && filemtime($uri) <= $info->timestamp) {
// The file is already imported and not changed since the last import.
// Remove it from file list and don't import it again.
unset($files[$uri]);
}
}
}
return locale_translate_batch_build($files, $options);
}
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!locale!locale.bulk.inc/function/locale_translate_batch_import_files/8.1.x