Index: votingapi.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/votingapi/votingapi.module,v
retrieving revision 1.46.2.10
diff -u -p -r1.46.2.10 votingapi.module
--- votingapi.module	7 Sep 2008 03:03:29 -0000	1.46.2.10
+++ votingapi.module	12 Sep 2008 18:30:59 -0000
@@ -86,11 +86,19 @@ function votingapi_settings_form($form_s
     ),
   );
 
+  if (module_exists('translation')) {
+    $form['votingapi_translation'] = array(
+      '#type' => 'radios',
+      '#title' => t('Translation handling'),
+      '#description' => t('On multilingual sites, translated content forms a <em>translation set</em>--all the different language versions of a given piece of content. This option lets you select a default behavior for multilingual content. Choose "Default" to have votes for each member of a translation set tallied separately. Choose "Aggregate" to have votes tallied from the full translation set, so that votes for any member of the translation set will count for all members.'),
+      '#options' => array('default' => t('Default: votes on translated content are calculated normally.'), 'aggregate' => t('Aggregate: votes on translated content are aggregated across the translation set.')),
+      '#default_value' => variable_get('votingapi_translation', 'default'),
+      '#weight' => -1,
+    );
+  }
   return system_settings_form($form);
 }
 
-
-
 /**
  * Cast a vote on a particular piece of content.
  *
@@ -422,10 +430,22 @@ function votingapi_recalculate_results($
 function _votingapi_get_standard_results($content_type, $content_id) {
   $cache = array();
 
+  $content_id = (array) $content_id;
+
+  // If the content type is node, aggregate across a translation set.
+  if ($content_type == 'node' && variable_get('votingapi_translation', 'default') == 'aggregate') {
+    $node = node_load($content_id);
+    if (translation_supported_type($node->type) && !empty($node->tnid) && $translations = translation_node_get_translations($node->tnid)) {
+      $content_id = array();
+      foreach ($translations as $translation) {
+        $content_id[] = $translation->nid;
+      }
+    }
+  }
   $sql  = "SELECT v.value_type, v.tag, ";
   $sql .= "COUNT(v.value) as value_count, SUM(v.value) as value_sum  ";
   $sql .= "FROM {votingapi_vote} v ";
-  $sql .= "WHERE v.content_type = '%s' AND v.content_id = %d AND v.value_type IN ('points', 'percent') ";
+  $sql .= "WHERE v.content_type = '%s' AND v.content_id IN (%d) AND v.value_type IN ('points', 'percent') ";
   $sql .= "GROUP BY v.value_type, v.tag";
   $results = db_query($sql, $content_type, $content_id);
 
@@ -441,7 +461,7 @@ function _votingapi_get_standard_results
   $sql .= "FROM {votingapi_vote} v ";
   $sql .= "WHERE v.content_type = '%s' AND v.content_id = %d AND v.value_type = 'option' ";
   $sql .= "GROUP BY v.value, v.tag";
-  $results = db_query($sql, $content_type, $content_id);
+  $results = db_query($sql, $content_type, implode(', ', $content_id));
   while ($result = db_fetch_array($results)) {
     $cache[$result['tag']][$result['value_type']]['option-'. $result['value']] = $result['score'];
   }
