The i18n_node table has translation id 0 for nodes that have no translation. When the translation module tries to find out if a node has a translation, it performs an inner join on the translation id. If several untranslated items exist, they will all have trid 0 and can be mistaken for translations of each other. To fix this, append ' AND a.trid != 0' to all such queries.
I found two of those queries in translation.module and fixed them (patch attached). Hopefully that's all of them.

CommentFileSizeAuthor
translation.module_0.patch1.32 KBBodo Maass

Comments

jose reyero’s picture

Status: Needs review » Needs work

I think the second part of the patch looks good.

But the first one, the trid != 0 condition is already in the conditions to be merged,
$conds[] = "b.trid != 0";
why do we need it again?

pepeek’s picture

Correct, the second part of the patch fixes the problem allright!

skoob’s picture

Regarding the trid, would it make sense to instead have trid equal the nid of the original node? That way you could easily find out which of the node is the original (ie WHERE trid=nid). AFAICS, there is no way in the current model to find that information (but i might be wrong, I've just started trying to figure out how the code works). This could be useful for things like figuring out whether a translation needs updating when the original has been modified.

You could still find nodes that don't have any translations by looking for trid's with only one entry (e.g. with GROUP BY and COUNT()).

BTW, what is the best place to discuss i18n development?

jose reyero’s picture

Status: Needs work » Fixed

Thanks, fixed

Anonymous’s picture

Status: Fixed » Closed (fixed)
apq’s picture

Hi,

Is it really fixed in the 5.x-2.4 version?

function translation_node_nid($nid, $language = NULL, $default = NULL) {
  $translation = db_result(db_query("SELECT n.nid FROM {i18n_node} n INNER JOIN {i18n_node} a ON n.trid = a.trid AND n.nid <> a.nid WHERE a.nid = %d AND n.language = '%s' AND n.trid is not null", $nid, $language ? $language : i18n_get_lang()));
  return $translation ? $translation : $default;
}

The default value for trid in i18n_node table is 0, so the condition AND n.trid is not null doesn't work. Changing it for AND n.trid <>0 works ok.

Thank's!