Chris@0: $operations, Chris@0: 'title' => t('Updating translations'), Chris@0: 'progress_message' => '', Chris@0: 'error_message' => t('Error importing translation files'), Chris@0: 'finished' => 'locale_translation_batch_fetch_finished', Chris@0: 'file' => drupal_get_path('module', 'locale') . '/locale.batch.inc', Chris@0: ]; Chris@0: return $batch; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Builds a batch to download and import project translations. Chris@0: * Chris@0: * @param array $projects Chris@0: * Array of project names for which to check the state of translation files. Chris@0: * Defaults to all translatable projects. Chris@0: * @param array $langcodes Chris@0: * Array of language codes. Defaults to all translatable languages. Chris@0: * @param array $options Chris@0: * Array of import options. See locale_translate_batch_import_files(). Chris@0: * Chris@0: * @return array Chris@0: * Batch definition array. Chris@0: */ Chris@0: function locale_translation_batch_fetch_build($projects = [], $langcodes = [], $options = []) { Chris@0: $projects = $projects ? $projects : array_keys(locale_translation_get_projects()); Chris@0: $langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list()); Chris@0: Chris@0: $batch = [ Chris@0: 'operations' => _locale_translation_fetch_operations($projects, $langcodes, $options), Chris@0: 'title' => t('Updating translations.'), Chris@0: 'progress_message' => '', Chris@0: 'error_message' => t('Error importing translation files'), Chris@0: 'finished' => 'locale_translation_batch_fetch_finished', Chris@0: 'file' => drupal_get_path('module', 'locale') . '/locale.batch.inc', Chris@0: ]; Chris@0: return $batch; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Helper function to construct the batch operations to fetch translations. Chris@0: * Chris@0: * @param array $projects Chris@0: * Array of project names for which to check the state of translation files. Chris@0: * Defaults to all translatable projects. Chris@0: * @param array $langcodes Chris@0: * Array of language codes. Defaults to all translatable languages. Chris@0: * @param array $options Chris@0: * Array of import options. Chris@0: * Chris@0: * @return array Chris@0: * Array of batch operations. Chris@0: */ Chris@0: function _locale_translation_fetch_operations($projects, $langcodes, $options) { Chris@0: $operations = []; Chris@0: Chris@0: foreach ($projects as $project) { Chris@0: foreach ($langcodes as $langcode) { Chris@0: if (locale_translation_use_remote_source()) { Chris@0: $operations[] = ['locale_translation_batch_fetch_download', [$project, $langcode]]; Chris@0: } Chris@0: $operations[] = ['locale_translation_batch_fetch_import', [$project, $langcode, $options]]; Chris@0: } Chris@0: } Chris@0: Chris@0: return $operations; Chris@0: }