Hi,

I'm not sure thats a bug, it's a behaviour that should be here in my point of view.

When clicking on the "create translation link" it would be nice if some terms of the former node has translations that those terms would be already set when rendering the form.

I see the need of this situation because many time I create a translation I forget to set up the terms.

Of course this feature only apply for vocabulary with no language.

I propose a patch that solve this situation. This patch only work if taxonomy module is loaded before translation module (see comment in the code)

This piece of code is located in translation.module/translation_form_alter function (see attachment)

  //MiC
  //if create translation is clicked 
  //we try to set the term belonging to a no-language vocabulary and 
  //selected in the former node in the new target language node
  //This patch only work if the weight of the taxonomy module is 
  //lighter than the weight of translation module (taxonomy module must 
  //be loaded before translation module). As I don't know how this 
  //patch is going to be appreciated i don't include this in my patch 
  //you should do it by changing the weight of taxonomy (or translation) in 
  //the system table, make sure translation is heavier than taxonomy. 
  if(preg_match("/node\/add\/(.*)\/translation\/([[:digit:]]+)\/([[:alpha:]]{2})/",request_uri(),$matches))
  {  
  	$node_type 	= $matches[1];
  	$node_id 	= $matches[2];
  	$lang 		= $matches[3];
  	//find the voculary associated to this node type
  	//we are sure to get only vocabularies adapted to this language
  	//ie no language vocabulary or vocabulary defined for the current language
  	$vocabularies = taxonomy_get_vocabularies($node_type);
  	$vids = "(".implode(",",array_keys($vocabularies)).")";
  	//find the term already selected for this node
  	//and belonging to $vids
  	//we can't use the taxonomy_node_get_terms($nid) function because 
  	//its query is rewritten for the current language  	
  	$sql = "SELECT 
  				t.tid
  			FROM 
  				{term_node} as tn, 
  				{term_data} as t
  			WHERE 
  				t.tid = tn.tid
  				AND
  				tn.nid = $node_id
  				AND
  				t.vid IN $vids";
  	
  	//using the "t.vid IN $vids" clause make sure that we're not getting
  	//term from other language vocabulary, because in $vids there's only
  	//vocabulary with no language or vocabulary with the current language.
  	//The presence of vocabulary with the current language in this array 
  	//is not a problem because they are bound to have no terms for this 
  	//node as it's a new one ...
  	
  	//get the translation for the current language 
  	//and put that in a nice array
  	$term_translated = array();
  	$result = db_query($sql);
  	while ($term = db_fetch_object($result)){
  		//debug($term);
  		$sql = "
  		SELECT 
  			t1.tid
  		FROM 
  			{term_data} as t1, 
  			{term_data} as t2
  		WHERE 
  			t1.trid = t2.trid 
  			AND
  			t1.language = '$lang'
  			AND 
  			t2.tid = $term->tid
  		";
  		//debug($sql);
  		$term_translated[] = db_fetch_object(db_query($sql));
  	}
  	//debug($term_translated);
  	
  	//now we must alter form
  	foreach ($term_translated as $term){
  		$default_value = array();
  		$default_value[] = $term->tid;
  		$form["taxonomy"][$term->vid]["#default_value"] = $default_value;
  	}
  }

Comments

michaelcourcy’s picture

Title: Setting the translated term when creating a translation » Setting the translated term when creating a translation (correction)
StatusFileSize
new25.56 KB

Sorry I made a mistake on the second request see attachement

jose reyero’s picture

Category: bug » feature

Yes, this feature would be nice.

I think this would be better implemented inside the 'translation_node_populate_fields'.

-- Please provide patches, not full modules

Thanks

xpereta’s picture

A very desirable feature indeed, Michael. Moreover on multilingual sites that use taxonomies heavily.

I'm currently needing something similar myself. However I intend to devise some mechanism to have the categories sinchronysed across all translations of the same node. For example, when you add or delete a term to a node that already has translations, that very term would be added or delete in the other nodes that are translations of that first one.

Of course this functionality of sinchronysed categories across translations should be optional, perhaps on a content-type basis.

jose reyero’s picture

Version: 4.7.x-1.x-dev » 5.x-1.x-dev
Assigned: Unassigned » jose reyero

I'll work on this for 5.x

jose reyero’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)