Allow sharing image files from different modules (image translations)

Jose Reyero - January 18, 2009 - 17:13
Project:Image
Version:6.x-1.x-dev
Component:image.module
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

I've been studying the code of the current image module (6.x) trying to find a way to create image translations (translated title and description) without duplicating the files, to be implemented in i18n module (i18n sync)
AFAIK, we would be ok about the data model (we'd just need to create additional rows in the image table), but given how the image module works there's no way we can plug into the image inserts and updates to do it.

As node translation is now a Drupal core feature I think this goes beyond i18n module compatibility being more a missing Drupal core feature when it comes to image nodes.

What we need here is not really the image module handling translations itself, but a way to prevent 'image_insert' from copying files around, when they're already existing files in the 'files' folder so we can do something like:

<?php
// This will be done by i18nsync module, if not by the image module itself
$translation->images = $original->images;
$translation->new_file = FALSE;

// and then a way to prevent image insert from copying files
function image_insert() {
  if (!empty(
$node->new_file)) {
   
// do insert operations
}
// otherwise, skip, other modules can do their work here and fill in the image table rows reusing a fid...
}
?>

Also for the image_delete() function we'd need a flag to prevent the module from deleting the files (as they may be linked too to other translations).

Please let me know whether this makes sense (I'd be posting a patch) or you can think of a better way of achieving the same.

Related i18n issue: #329825: i18n/image: How to translate a picture? ;) i18nsync_fields_node_image not working

#1

sun - January 18, 2009 - 18:43
Title:Alow sharing image files from different modules (image translations)» Allow sharing image files from different modules (image translations)

At which layer does i18nsync perform those alterations? form_alter() or nodeapi('load'/'prepare')? I'm asking, because I only know Translatable's approach and flow, which mostly works in the FAPI layer.

#2

Jose Reyero - January 18, 2009 - 19:28

Mostly on nodeapi, but the module is a collection of hacks to support other modules/fields translatability and synchronization, so we take whatever approach is needed by each of the other modules.

Ideally, each node module would take care of its own translations (i.e. for image module, it might copy over the original image using _nodeapi('prepare translation'), but allow it to be replaced as sometimes different translations may mean different images). Well, that may be a feature request too.

As the multilingual support varies for each contrib module, we have this i18nsync module that takes care of all what other contrib modules don't do plus some synchronization (updating all translations when you update one of the nodes)...

#3

sun - January 18, 2009 - 20:02

Hm. I still have little idea of what would be required for i18nsync, because I do not know its flow. I can only guess that the node's title and description (body) is already covered in i18nsync's process. Anyway, if you see a way that would make it compatible, please feel free to post a patch.

That said, I guess that it should be configurable per image (node) whether the image file is synced or not. If you consider a technical screenshot of an application, one might want to provide a different screenshot per language, while other images on the site can be happily synced. (That's why Translatable works at the FAPI layer, so it would be basically able to allow more granular translation flows like this)

#4

Jose Reyero - January 21, 2009 - 23:46
Status:active» needs review

This patch allows sharing image files in translations. What it does in detail:
- When creating a translation, the image is pre-populated with the source node's image (unless a new image is uploaded)
- When updating/deleting a image node, just delete the actual file when it is not linked to any other node

This way, when you create a translation you have the option of keeping the same image or uploading a new one. This is not related to i18nsync, though if this patch gets in I'll be able to add additional sync features on top of it....

AttachmentSize
image_translation.patch 3.59 KB

#5

AltoRetrato - February 21, 2009 - 20:55

I spent days reading documentation, searching with Google and pulling my hair out... and finally I found your patch. It seems to work like a charm. Great job, Jose, and thanks for sharing!

#6

AltoRetrato - February 23, 2009 - 16:02

P.S.: Even though I can translate the name and description of images with this patch, I can't find a way to translate the name and description of galleries. I found (Home › Administer › Site building › Translate interface › Search) and tried to translate the taxonomy strings, and also put the t() function in image_galley.module where it was missing (t($gallery->name) and t($gallery->description)), but the title and description always shows up without translation. For now, I'm using string overrides in settings.php, but it is such an ugly hack...

Does anyone know of a better solution?

#7

Jose Reyero - February 23, 2009 - 16:55

@AltoRetrato,
>P.S.: Even though I can translate the name and description of images with this patch, I can't find a way to translate the name and description of galleries

This is a completely different issue, unrelated with what this patch does

Thanks for testing the patch

#8

JensVejmand - March 18, 2009 - 18:57

Tried out the patch just now: Solves my problem with double-uploading images.

Thanks. Hopes this comes into the Image module.

#9

sun - March 21, 2009 - 00:08

I like this patch in general. However, we want to add some tests to ensure that the expected logic works (and keeps working).

#10

sun - March 23, 2009 - 20:56

#403142: Keep some info across translations has been marked as duplicate of this issue. I see that this issue implements the possibility to assign a single file to multiple image nodes (translations) while ensuring that the file is not deleted when there is still a node referencing the file left.

#11

psc - April 13, 2009 - 12:09

Please, please...

- Is this ready for production sites?

- Any alternative for those of us who are too ignorant to apply patches and/or are nor able to apply them?

- Any altruist soul wanting to help me applying the patch?

I have a photography site in three languages and also another one in two languages that will have lots of images ! This could make my life much happier !

Thanks in advance !

psc

#12

tomsm - April 22, 2009 - 08:36

When will this be added to the Image module?
I need to translate the title of my images.
Thanks!

#13

ikeizer - May 17, 2009 - 12:38

What's the status on this? Is this being implemented already? Thanks.

#14

tomsm - May 27, 2009 - 20:44

subscribing....

#15

hop - June 19, 2009 - 07:45

When I apply this image_translation.patch, I don't see any images with neutral language (explicit language is OK). Thanks a lot

#16

sun - July 12, 2009 - 19:17

Re-rolled with some minor adjustments.

I need some positive confirmations that this patch works with Translation module being enabled, but also doesn't break functionality without it.

AttachmentSize
image.translation.patch 4.09 KB

#17

guaka - July 23, 2009 - 18:06

image_translation.patch from #4 works.
Though the first time saving it didn't store my translated title.

#18

sun - August 2, 2009 - 01:52
Status:needs review» fixed

I'm trusting your expertise, Jose.

Thanks for reporting, reviewing, and testing! Committed to 6.x.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

#19

System Message - August 16, 2009 - 02:00
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

#20

convulsion - September 10, 2009 - 06:56

Hi,

I still have this problem. Using the newest version of Image, which should have this patch included, but can't get it to work.

Jose said:
- When creating a translation, the image is pre-populated with the source node's image (unless a new image is uploaded)

...and this does not happen. I click on translate > add translation from the source image, but the image upload field is empty and not pre-populated like it should. If I try to submit the post, it won't let me, since there is no image. Don't really get what can be wrong, should I have any other settings enabled in addition to the normal i18n stuff which allows translating images in the first place?

Happy to tell you more about my settings and modules if this isn't enough.

#21

convulsion - September 10, 2009 - 06:59
Category:feature request» support request
Status:closed» active

#22

convulsion - September 14, 2009 - 07:34
Category:support request» feature request
Status:active» closed

This got fixed by updating to the latest dev versions of the Image module and the i18n module.

#23

jagdfalke - September 20, 2009 - 00:41
Category:feature request» support request
Status:closed» active

This patch doesn't seem to do anything over here.

I'm using image-6.x-1.0-beta3 and i18n-6.x-1.1 with Drupal 6.14. When I click on "add translate" for an image node, the form to create the translated note doesn't contain an image.

Do I need to use the dev version of i18n?

Regards,
Milan

#24

Jose Reyero - September 22, 2009 - 00:02
Status:active» closed

@jagdfalke
Wait for next versions of both modules.

#25

sun - September 22, 2009 - 00:14
Category:support request» feature request
Status:closed» fixed

@Jose: Any time-frame or similar for the next release of i18n? :) AH! And btw: #549698: Prepare field label and description for DDT (translatable queries) - see you over there! :-D

#26

System Message - October 6, 2009 - 00:20
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.