--- contributions/modules/autolocale/autolocale.module	2007-04-12 23:55:23.000000000 +0200
+++ autolocale.module	2007-05-03 08:55:43.000000000 +0200
@@ -93,7 +93,7 @@
 
   // Initiate batch processing of import if files are available
   if ($batch = autolocale_batch_import($form_values['language'])) {
-    return drupal_set_batch($batch);
+    return batch_set($batch);
   }
   // Return to language page otherwise
   else {
@@ -121,29 +121,36 @@
   while ($component = db_fetch_object($result)) {
     $files = array_merge($files, _autolocale_po_files_for_component($language, $component));
   } 
-
-  // Build a batch array, if we have files to import
   if (count($files)) {
     $ops = array();
     foreach($files as $filename) {
-      $ops[] = array(
-        'callback' => '_autolocale_do_import',
-        'arguments' => array($filename, $language)
-      );
+      // We call _autolocale_do_import every batch operation. Arguments to this
+      // function are: $filename, $language
+      $ops[] = array('_autolocale_do_import', array($filename, $language));
     }
-    
+  }
+  return autolocale_build_batch($ops);
+}
+/**
+ * Build a batch from array of files.
+ *
+ * @param $operations
+ *   Array of operations to perform
+ * @return
+ *   A batch structure
+ */
+function autolocale_build_batch($operations) {
+  if (count($operations)) {
     $batch = array(
-      'title'             => t('Importing interface translations'),
-      'init_message'      => t('Starting import'),
-      'error_message'     => t('Error importing interface translations'),
-      'progress_message'  => t('Remaining @remaining of @total.'),
-      'finished_callback' => 'autolocale_batch_finished',
-      'operations' => $ops,
-    );
-
+        'operations' => $operations,
+        'title'             => t('Importing interface translations'),
+        'init_message'      => t('Starting import'),
+        'progress_message'  => t('Remaining @remaining of @total.'),
+        'error_message'     => t('Error importing interface translations'),
+        'finished' => 'autolocale_batch_finished',
+        );
     return $batch;
   }
-
   return FALSE;
 }
 
@@ -159,6 +166,7 @@
  */
 function _autolocale_do_import($filepath, $langcode, &$results) {
   include_once "includes/locale.inc";
+  drupal_set_message(t("Importing $filepath")); // @TODO - see MARK
   $file = (object) array('filename' => basename($filepath), 'filepath' => $filepath);
   _locale_import_read_po('db-store', $file, 'keep', $langcode);
   $results[] = $filepath;
@@ -167,12 +175,14 @@
 /**
  * Batch hook called when processing finishes.
  */
-function autolocale_batch_finished($batch, $success, $results) {
+function autolocale_batch_finished($success, $results) {
   if ($success) {
-    $message = format_plural(count($results), '1 interface translation file imported.', '@count interface translation files imported.');
+    // @TODO - MARK realize how $results work and implement it instead of printing every file
+    // $message = format_plural(count($results), '1 interface translation file imported.', '@count interface translation files imported.');
+    $message = t('Translations succesfully imported');
   }
   else {
-    $message = t('Finished with an error.');
+    $message = t('Importing translations finished with an error.');
   }
   drupal_set_message($message);
   return t('Automatic import finished.');
@@ -209,13 +219,25 @@
           include_once 'autolocale.install';
           // Import all PO files for all enabled foreign languages
           $languages = array_keys(_autolocale_languages());
+          $ops = array();
           foreach($new as $module) {
             $component = db_fetch_object(db_query("SELECT name, filename FROM {system} WHERE name = '%s'", $module));
             foreach($languages as $langcode) {
-              //_autolocale_import_po_files_for_component($langcode, $component);
-              // @todo tie into batch import later.
+              // Get all files needed for batch operation
+              $files = _autolocale_po_files_for_component($langcode, $component);
+              if (count($files)) {
+                foreach($files as $filename) {
+                  // Schedule an operation for each one
+                  $ops[] = array('_autolocale_do_import', array($filename, $langcode));
+                }
+              }
             }
           }
+          if (count($ops)) {
+            $batch = autolocale_build_batch($ops);
+            // TODO - this doesn't work
+            batch_set($batch);
+          }
           _autolocale_clear();
         }
       }
