I am struggling with a misbehaviour of the file entity module (supposedly). If I change the language with the language switcher alt and title texts stay on the language that was active at the last cache flush or the resaving of the node. Is it some kind of cacheing issue?
IF I change the format of the image field to 'rendered file' on the content display settings page everything seems to be working fine, alt tags and titles show up properly. However most sites use image styles, other formatters like flex slider, colorbox etc, therefore it is an important functionality.

I could reproduce the problem on sympletest.me and on my test environment as well.

I use the latest media module, file entity and entity translation modules.

1. Core and Basic module installation on one language
3. Enabled 1 more language
2. File Entity configuration -> in TRANSLATABLE ENTITY TYPES image is configured with the following options:
- Hide language selector
- Exclude Language neutral from the available languages
- Prevent language from being changed once the entity has been created
4. Created custom content type for testing
- Content type is translatable with entity translation
- Added image field with media file selector widget not translatable (unlimited values)
- Configured display settings of the image field format to 'image'.
3. Uploaded single or multiple image files through content/files/add files or via media widget, does not make a difference
4. After upload I translated Alt and title fields on multiple images through content/files/edit/translate
5. Added images to the content's image field through media browser
6. After saving and/or cache flushing, my alt and title tags stays on the language (regardless of the chosen language) that was active.

I created more related issues on this while I was trying to investigate. Thanks David_Rothstein for giving a clue quoted here:

This does seem like it could be a caching issue. If I understand the code flow correctly, the File Entity module is setting the alt and title when the field is loaded, but from https://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/fun... you can see that the loaded field data gets cached.

Possibly File Entity shouldn't be setting such dynamic properties in this hook (or at least not only setting them in this hook; it could set them again later I suppose in code that doesn't get cached)...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hefterbrumi created an issue. See original summary.

hefterbrumi’s picture

Issue summary: View changes
hefterbrumi’s picture

Title: Image Alt and Title displayed in the wrong language » Image Alt and Title displayed in the wrong language IF field format is not "rendered file"
hefterbrumi’s picture

Unfortunately I still can't resolve this. Anybody else has this bug?

Yazzbe’s picture

I have the same problem with entity translation and bxslider / colorbox.

A cache flush makes the correct alt/title translation visible for a specific language.
Changing the language, requires again a cache flush to see the proper translation.

caching issue ?

joseph.olstad’s picture

I confirm same issue is occuring here. Only 'rendered file' is able to provide the correct field language for alt text and title text of the file/image.

joseph.olstad’s picture

I've spent some time looking into the above comments but didn't come up with anything yet.

Not sure if the issue below will provide any additional insight.
#2017647: Media browser translatable alt and title fields for translatable parent entity

joseph.olstad’s picture

My use-case is views.
I made one useful discovery:

function file_entity_field_formatter_view is not called when 'image' formatter is selected, however it IS called when Rendered file is chosen on the field configuration for the view.

So, if image has any formatter_view it might be handled by perhaps another implementation of formatter_view but not the one in the file_entity module.

**EDIT**

found another formatter_view hook that suspect provides 'image'
media/mediafield/mediafield.module
also possibly
includes/media.fields.inc

....to be continued

joseph.olstad’s picture

**EDIT** see core patch here that fixes this forever: #2835135: image formatter needs to handle alt/title from file entities on images for multi language support

The D8 issue #2735111: Decide how to handle alt/title on images when core formatter is used seems to me to explain the problem, it appears that D8 has the exact same problem and if that issue gets resolved we can probably backport it to D7 unless of course we fix this in D7 first and then port the fix to D8. Either way, my current focus is fixing this in D7. See the patch


NOTE: as a workaround, if you still want image styles when using 'Rendered File' (because Rendered File provides the alt and title in the correct language) you can create a tpl file for the field and do something similar as follows:

/** NOTE, this example is based on a view tpl **/
        //need to apply image style
        //news_listing is the image style required
        preg_match('/\/sites\/internetsitedotcom\/files\/(.*\.jpe?g|.*\.png)\"/i', $row, $matchesTest);
        if (isset($matchesTest[1])) {
          //there is an image and we need to style it
          $pathBigImage = $matchesTest[1];
          $pathSmallImage = 'public://' . $matchesTest[1];
          $pathSmallImage = image_style_url('news_listing', $pathSmallImage);
          preg_match('/\/files\/(.*\.*)/i', $pathSmallImage, $matchesTestSmall);
          $pathSmallImage = $matchesTestSmall[1];
          $row = preg_replace("/" . str_replace("/","\\/",$pathBigImage) . "/", $pathSmallImage, $row);
        }
joseph.olstad’s picture

So, if I understand correctly the issue #2735111 it looks like we'll have to fix this by writing a D7 core patch because the core formatter for image is not correctly using file_entity .

joseph.olstad’s picture

I just finished writing a small core patch for D7 fixes this issue. Patch to follow shortly.

joseph.olstad’s picture

joseph.olstad’s picture

Version: 7.x-2.0-beta2 » 7.x-2.10
Status: Active » Needs work
Related issues: +#2835135: image formatter needs to handle alt/title from file entities on images for multi language support

This is still an issue, the core patch I wrote does fix the problem,
[#11824241-1]
but it would be nice if we didn't have to patch core , would be nice to resolve this in file_entity instead of core.

David_Rothstein’s picture

Version: 7.x-2.10 » 7.x-2.x-dev
Status: Needs work » Needs review
FileSize
3.26 KB

Here's a patch that tries what I suggested in the long-ago quote mentioned in the issue summary. It's kind of ugly, but it seems to work, and it doesn't depend on a particular image formatter being used (unlike the core patch).

I tested this with a regular image attached to a node which was displayed using the Image module formatter, an image attached to a field collection on a node which was displayed using the Image module formatter, and an image attached to a node which was displayed using the Colorbox module's formatter. I also tested with and without the Entity Cache module. Seemed to work correctly in all cases. Definitely needs review and testing by others though.

joseph.olstad’s picture

@david_rothstein, thank you so much for that patch. I backed off the core patch, cleared caches, applied your patch and tested, looks great !!!

joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community

  • David_Rothstein authored 1782158 on 7.x-2.x
    Issue #2665960 by David_Rothstein: Image Alt and Title displayed in the...

  • David_Rothstein authored 1782158 on 7.x-3.x
    Issue #2665960 by David_Rothstein: Image Alt and Title displayed in the...
joseph.olstad’s picture

Status: Reviewed & tested by the community » Fixed
joseph.olstad’s picture

FYI, someone has reported an issue that might be a regression but not sure I haven't noticed anything myself yet and I haven't yet taken the time to really understand what this other issue is.

they've supplied a patch, haven't yet reviewed.

#2918049: Image field alt and title text overridden by file_entity_alt and file_entity_title

Status: Fixed » Closed (fixed)

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

joseph.olstad’s picture

FYI:
there is a related performance enhancement /fix that touches the code that was committed in this issue.

#2966026-2: Performance fix - rename file_entitycache_file_load to file_entity_entitycache_file_load

Appreciate a review of the new patch
see
#2966026-2: Performance fix - rename file_entitycache_file_load to file_entity_entitycache_file_load

and I also (with FabianX's guidance) rolled a somewhat related performance patch here too:
#2642764-34: Speed up via shortcutting token file_entity_file_load