On a multilingual site, for example using English and Spanish languages, when using media image fields the translated media values (e.g alt and title) aren't being used but instead the default language version is always being used.
To resolve in the file: /src/Plugin/Field/FieldFormatter/PhotoswipeFieldFormatter.php I changed the code as shown below.
from (Photoswipe v4.0.1):
// Check if the entity is an Entity (e.g. wasn't deleted) and the entity
// is accessible:
if ($item->entity instanceof EntityInterface && $item->entity->access('view')) {
$elements[$delta] = [
'#theme' => 'photoswipe_image_formatter',
'#item' => $item,
'#entity' => $items->getEntity(),
'#display_settings' => $settings,
'#delta' => $delta,
];
}
to:
// Check if the entity is an Entity (e.g. wasn't deleted) and the entity
// is accessible:
if ($item->entity instanceof EntityInterface && $item->entity->access('view')) {
// Get the translated version of the referenced entity.
$translated_entity = $this->entityRepository->getTranslationFromContext($item->entity, $langcode);
// Use translated media entity for the item.
$item->entity = $translated_entity;
$elements[$delta] = [
'#theme' => 'photoswipe_image_formatter',
'#item' => $item,
'#entity' => $items->getEntity(),
'#display_settings' => $settings,
'#delta' => $delta,
];
}
Which I found resolved the issue.
Active
4.0
Code