keywords: files, file_revisions, image, internationalization, i18n, translate.module, image.module, 5.x, translated image not showing
versions:
// $Id: translation.module,v 1.3.2.3 2007/02/03 00:16:34 jareyero Exp $
// $Id: image.module,v 1.209.2.2 2007/01/13 06:47:53 walkah Exp $
Hi,
Just wanted to share what kept me from using i18n with the image module.
From 5.x onwards, it seems as if i18n uses file revisions when translating nodes with attachements.
This results on the one hand in new lines in file_revisions, but on the other offers the big advantage that you don't have to upload the image in the translated node again.
The image module currently doesn't reflect this as it uses [in hook_load] a db_query that references the files table.
Result: The translated nodes can't show the referenced images.
I managed to change the code in image.module in a way that it looks into file_revisions.
Done by replacing in image.module in hook_load
$result = db_query("SELECT filename, filepath FROM {files} WHERE nid=%d", $node->nid);
by
$result = db_query("SELECT filename, filepath FROM {files} f INNER JOIN {file_revisions} r ON f.fid = r.fid WHERE r.vid = %d", $node->vid);
Maybe some developer can confirm that this is actually the right way...
PS: If you happened to have changed the names of the files in the translated node, this patch doesn't reflect this. The new names would be stored in the column description in the table file_revisions. I didn't change the code, because the entries for the original files (with the derivatives) that are copied into file_revisions have no values in the column description. And I have no clue why... ;-)
PS: There are still some issues, like hook_update and hook_delete not reflecting the additional file_revisions table. Scenario: You create an image in EN, translate it into FR; the table files contains three lines (original, preview, thumbnail), table file_revisions contains twice three lines (once for EN, once for FR); you delete the EN image; image.module would currently not check for revisions referencing the files and thus deletes the files; result is that the FR node references files that are no longer there...
Summary: Not ideal but maybe a step in the right direction.
Marcus
Comments
Comment #1
doerings_net commentedOne step closer:
If you replace in _image_insert
db_query("INSERT INTO {file_revisions} (fid, vid, description, list) VALUES (%d, %d, '%s', %d)",
$fid, $node->vid, '', 0);
with
db_query("INSERT INTO {file_revisions} (fid, vid, description, list) VALUES (%d, %d, '%s', %d)",
$fid, $node->vid, $file->filename, 0);
we can use the description from file_revisions.
So instead of
$result = db_query("SELECT filename, filepath FROM {files} f INNER JOIN {file_revisions} r ON f.fid = r.fid WHERE r.vid = %d", $node->vid);
we can now use in image_load
$result = db_query('SELECT r.description AS filename, f.filepath FROM {files} f INNER JOIN {file_revisions} r ON f.fid = r.fid WHERE r.vid = %d', $node->vid);
Still the issues with hook_update and hook_delete, though.
Comment #2
drewish commentedPlease submit these changes as a patch, it makes it much easier to see precisely what changes you're making. See http://drupal.org/patch for more information.
Comment #3
drewish commentedComment #4
sunSorry, without further information this issue can only be marked as won't fix.