Index: quiz.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/quiz/quiz.module,v
retrieving revision 1.137.2.84
diff -u -p -r1.137.2.84 quiz.module
--- quiz.module	2 Mar 2010 17:36:58 -0000	1.137.2.84
+++ quiz.module	15 Mar 2010 16:08:40 -0000
@@ -2255,7 +2255,7 @@ function _quiz_get_random_questions(/*$n
   $questions = array();
   if ($num_random > 0) {
     if ($tid > 0) {
-      $questions = _quiz_get_random_taxonomy_question_ids($tid, $num_random);
+      $questions = _quiz_get_random_taxonomy_question_ids($tid, $num_random, $quiz->language);
       /*
       // Select random questions by taxonomy.
       $term = taxonomy_get_term($tid);
@@ -2299,14 +2299,58 @@ function _quiz_get_random_questions(/*$n
  * @return
  *  Array of nid/vid combos, like array(array('nid'=>1, 'vid'=>2)).
  */
-function _quiz_get_random_taxonomy_question_ids($tid, $num_random) {
+function _quiz_get_random_taxonomy_question_ids($tid, $num_random, $lang = NULL) {
   if ($tid == 0) {
     return array();
   }
 
   // Select random questions by taxonomy.
-  $term = taxonomy_get_term($tid);
-  $tree = taxonomy_get_tree($term->vid, $term->tid);
+  if (defined('_QUIZ_TAXONOMY_GET_TERM')) {
+    //Use alternate implementation of taxonomy_get_term, used by tests to avoid
+    //caching in a static variable in function scope.
+    $term = call_user_func(_QUIZ_TAXONOMY_GET_TERM, $tid);
+  }
+  else {
+    $term = taxonomy_get_term($tid);
+  }
+
+  if($term && $lang && function_exists('i18ntaxonomy_vocabulary')) {
+    switch (i18ntaxonomy_vocabulary($term->vid)) {
+      case I18N_TAXONOMY_TRANSLATE:
+        //This term belongs to a multilingual vocabulary.
+        if ($lang != $term->language) {
+          //Use term translation to select question
+          $term = reset(i18ntaxonomy_translate_terms(array($term), $lang));
+          $use_i18ntaxonomy_get_tree = function_exists('i18ntaxonomy_get_tree');
+        }
+        break;
+      case I18N_TAXONOMY_LANGUAGE:
+        //This term belongs to a vocabulary with a global language.
+        $vocabulary = taxonomy_vocabulary_load($term->vid);
+        if ($lang != $vocabulary->language) {
+          return array();
+        }
+        break;
+      case I18N_TAXONOMY_LOCALIZE:
+        //Terms are common for all languages.
+      case I18N_TAXONOMY_NONE:
+        // No multilingual options for this vocabulary.
+      default:
+        break;
+    }
+  }
+
+  if (!$term) {
+    return array();
+  }
+
+  if ($use_i18ntaxonomy_get_tree) {
+    $tree = i18ntaxonomy_get_tree($term->vid, $lang,  $term->tid);
+  }
+  else {
+    $tree = taxonomy_get_tree($term->vid, $term->tid);
+  }
+  
 
   // Flatten the taxonomy tree, and just keep term id's.
   $term_ids[] = $term->tid;
@@ -2318,20 +2362,30 @@ function _quiz_get_random_taxonomy_quest
   $term_ids = implode(',', $term_ids);
 
   // Get all published questions with one of the allowed term ids.
-  $result = db_query_range("SELECT n.nid, n.vid
-    FROM {node} n
-    INNER JOIN {term_node} tn USING (nid)
-    WHERE n.status = 1 AND tn.tid IN ($term_ids)
-    AND n.type IN ('"
-    . implode("','", array_keys(_quiz_get_question_types()))
-    . "') ORDER BY RAND()", 0, $num_random);
+  if($term_ids) {
+    $sql = "SELECT n.nid, n.vid
+      FROM {node} n
+      INNER JOIN {term_node} tn USING (nid)
+      WHERE n.status = 1 AND tn.tid IN ($term_ids)
+      AND n.type IN ('"
+      . implode("','", array_keys(_quiz_get_question_types()))
+      . "')";
+    if ($lang) {
+       $sql .= " AND n.language = '%s' OR n.language = ''";
+    }
+    $sql .= " ORDER BY RAND()";
+    $result = db_query_range($sql, $lang, 0, $num_random);
 
-  $questions = array();
-  while ($question_node = db_fetch_array($result)) {
-    $questions[] = $question_node;
-  }
+    $questions = array();
+    while ($question_node = db_fetch_array($result)) {
+      $questions[] = $question_node;
+    }
 
-  return $questions;
+    return $questions;
+  }
+  else {
+    return array();
+  }
 }
 
 /**
