5 * The API for download and import of translations from remote and local sources.
9 * Load the common translation API.
11 // @todo Combine functions differently in files to avoid unnecessary includes.
12 // Follow-up issue: https://www.drupal.org/node/1834298.
13 require_once __DIR__ . '/locale.translation.inc';
16 * Builds a batch to check, download and import project translations.
18 * @param array $projects
19 * Array of project names for which to update the translations. Defaults to
20 * all translatable projects.
21 * @param array $langcodes
22 * Array of language codes. Defaults to all translatable languages.
23 * @param array $options
24 * Array of import options. See locale_translate_batch_import_files().
27 * Batch definition array.
29 function locale_translation_batch_update_build($projects = [], $langcodes = [], $options = []) {
30 module_load_include('compare.inc', 'locale');
31 $projects = $projects ? $projects : array_keys(locale_translation_get_projects());
32 $langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list());
33 $status_options = $options;
34 $status_options['finish_feedback'] = FALSE;
36 // Check status of local and remote translation files.
37 $operations = _locale_translation_batch_status_operations($projects, $langcodes, $status_options);
38 // Download and import translations.
39 $operations = array_merge($operations, _locale_translation_fetch_operations($projects, $langcodes, $options));
42 'operations' => $operations,
43 'title' => t('Updating translations'),
44 'progress_message' => '',
45 'error_message' => t('Error importing translation files'),
46 'finished' => 'locale_translation_batch_fetch_finished',
47 'file' => drupal_get_path('module', 'locale') . '/locale.batch.inc',
53 * Builds a batch to download and import project translations.
55 * @param array $projects
56 * Array of project names for which to check the state of translation files.
57 * Defaults to all translatable projects.
58 * @param array $langcodes
59 * Array of language codes. Defaults to all translatable languages.
60 * @param array $options
61 * Array of import options. See locale_translate_batch_import_files().
64 * Batch definition array.
66 function locale_translation_batch_fetch_build($projects = [], $langcodes = [], $options = []) {
67 $projects = $projects ? $projects : array_keys(locale_translation_get_projects());
68 $langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list());
71 'operations' => _locale_translation_fetch_operations($projects, $langcodes, $options),
72 'title' => t('Updating translations.'),
73 'progress_message' => '',
74 'error_message' => t('Error importing translation files'),
75 'finished' => 'locale_translation_batch_fetch_finished',
76 'file' => drupal_get_path('module', 'locale') . '/locale.batch.inc',
82 * Helper function to construct the batch operations to fetch translations.
84 * @param array $projects
85 * Array of project names for which to check the state of translation files.
86 * Defaults to all translatable projects.
87 * @param array $langcodes
88 * Array of language codes. Defaults to all translatable languages.
89 * @param array $options
90 * Array of import options.
93 * Array of batch operations.
95 function _locale_translation_fetch_operations($projects, $langcodes, $options) {
98 foreach ($projects as $project) {
99 foreach ($langcodes as $langcode) {
100 if (locale_translation_use_remote_source()) {
101 $operations[] = ['locale_translation_batch_fetch_download', [$project, $langcode]];
103 $operations[] = ['locale_translation_batch_fetch_import', [$project, $langcode, $options]];