Problem/Motivation

Found out that when using a custom field as te caption for Photoswipe images, the caption is not being translated to the current site language it is always displayed in the original node language.

Steps to reproduce

1. Select display field format as Photoswipe.
2. Choose a custom text field as the photoswipe caption.
3. Visit node in different languages.
4. The caption is always in the original language, not translated.

Proposed resolution

Include current language from language_manager to get translation of caption field.

Issue fork photoswipe-3476006

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

cristianalcaraz created an issue. See original summary.

anybody’s picture

Thanks for the feedback @cristianalcaraz. Looks like the issue is here:
https://git.drupalcode.org/project/photoswipe/-/blob/5.x/modules/photosw...

Seems the entity needs to be loaded in the current language if translated (from context): https://www.drupal.org/docs/drupal-apis/entity-api/entity-translation-api

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...

anybody’s picture

Title: Dynamic caption submodule field translation » Dynamic caption submodule missing field translation
Status: Active » Needs work

I think this is the best resource for the correct implementation: https://drupal.stackexchange.com/questions/180660/get-translated-field-v...

@cristianalcaraz would you like to give it a try?

cristianalcaraz’s picture

Thank for your tips @anybody :)
I will try it!

bgreco’s picture

This patch fixes the issue when rendering a Media field. Not sure if it's still an issue when rendering an Image field.

anybody’s picture

Version: 5.0.0 » 5.x-dev

@bgreco please use a MR, not patches. Thanks!

grevil made their first commit to this issue’s fork.

grevil’s picture

Status: Needs work » Needs review

The fix provided will work for both media and file.

anybody’s picture

Status: Needs review » Reviewed & tested by the community

Perfect, thanks @grevil! :)

anybody’s picture

  • grevil committed 630ce520 on 5.x
    Issue #3476006: Dynamic caption submodule missing field translation
    
grevil’s picture

Status: Reviewed & tested by the community » Fixed

Thanks all!

Status: Fixed » Closed (fixed)

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