Multi-language support status

Events happening in the community are now at Drupal community events on www.drupal.org.
pbuyle's picture

What is the current status of multi-language support in Quiz ?

According to [#285570] should be fixed. But when looking at the code in quiz.module in 6.x-3.4, I don't see any reference to language. So it seems that it was dropped in Quiz 3. In Quiz 4, language is only used when copying questions of a translated Quiz.

I'm specifically interested in random selection of questions using a taxonomy term. I'm working on a patch for Quiz 6.x-3.4 to handle multi-languages (ie. node's language) and i18ntaxonomy in _quiz_get_random_taxonomy_question_ids(). So I wonder if there is a ongoing effort for multi-languages support that I can join or if I should fill a new issue for this.

Here is my patched version of _quiz_get_random_taxonomy_question_ids().

<?php
/**
* Given a term ID, get all of the question nid/vids that have that ID.
* @param $tid
*  Integer term ID.
* @return
*  Array of nid/vid combos, like array(array('nid'=>1, 'vid'=>2)).
*/
function _quiz_get_random_taxonomy_question_ids($tid, $num_random, $lang = NULL) {
  if (
$tid == 0) {
    return array();
  }

 
// Select random questions by taxonomy.
 
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 questions
         
$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;
  if (
is_array($tree)) {
    foreach (
$tree as $term) {
     
$term_ids[] = $term->tid;
    }
  }
 
$term_ids = implode(',', $term_ids);

 
// Get all published questions with one of the allowed term ids.
 
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'";
    }
   
$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;
    }

    return
$questions;
  }
  else {
    return array();
  }
}
?>

Comments

Patch

pbuyle's picture

I filled an issue with my patch, see http://drupal.org/node/742938

Quiz

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: