Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 5 replies, has 2 voices.

Last updated by Prosenjit Barman 1 year, 7 months ago.

Assisted by: Prosenjit Barman.

Author Posts
November 8, 2023 at 8:24 am #14753477

xavierC-7

I am using a wp gallery field to return a list of images,
I have several image_sizes in my custom wp theme, including :
add_image_size( 'product-swiper', 440, 535, true );
add_image_size( 'product-swiper-hd', 880, 1070, true );

At some point in my theme development, the image sizes were as follow :
add_image_size( 'product-swiper', 425, 535, true );
add_image_size( 'product-swiper-hd', 850, 1070, true );

I used regenerate thumbnails to regenerate all the image sizes, and chose "delete unused image sizes" and also "do not skip already existing image sizes" to be sure of a clean slate.

This is the code that returns my gallery images in a foreach statement :
<img class="gallery-image" width="<?= $gal_img['sizes']['container-med-third-width'];?>"
height="<?= $gal_img['sizes']['container-med-third-height'];?>"
src="<?= $gal_img['sizes']['container-med-third'];?>"
srcset="<?= $gal_img['sizes']['container-med-third'];?> 1x, <?= $gal_img['sizes']['container-med-third-hd'];?> 2x"
alt="<?= $gal_img['alt'];?>" data-light="lightbox"
onclick="swiperLight.slideTo(<?= $galerie_count;?>,0)" role="button">

Works well in the main language (french) and returns the image with 440 width and 535 height.

in the secondary language this is what is returned :
<img class="gallery-image" width="425" height="535" src="hidden link" srcset="hidden link 1x, hidden link 2x" alt="Ease, la nouvelle collection de salle de bains Inbani par Note Design Studio" data-light="lightbox" style="height: 522px;">

So the image is broken and returns a 404, I tried deleting the images from the gallery field of the main language and putting them in again, but it does not work.

I tried deleting the translation and translating again, but it still returns outdated data, why ?

November 8, 2023 at 11:55 am #14756125

xavierC-7

I continued my investigations, and I can see that in the media gallery, the same image has different ID in different language.
I might have done an issue myself because I know that at some point I installed wpml media translations, but then realized I didn't have the use for it and disabled it.
And while searching in the database I can see that all the files (_wp_attachment_metadata) that have the wrong width/height value have english ID of the images.
Is there a way to undo the installation of wpml media translations ?

November 8, 2023 at 12:11 pm #14756221

xavierC-7

Ok so I still continued my investigations and find out that if I regenerate thumbnails for the image WHILE i'm in the secondary language in the dashboard, it fixes the image size.
I just started regenerate thumbnails on ALL images while in the secondary language in the dashboard. It takes 7 hours to complete.

I'll keep you updated.

But I still have a question, is it normal that even if I don't use media translation, my images don't have the same ID when I change language in the media library?
Or is it a side effect of the installation and activation of media translation?
And if yes, is it reversible?

November 9, 2023 at 9:54 am #14764193

Prosenjit Barman
WPML Supporter since 03/2023

Languages: English (English )

Timezone: Asia/Dhaka (GMT+06:00)

Hello There,
Thanks for contacting WPML Support.

I understand the issue and it's great to hear that you have already identified a solution for it!

In response to your question- When Media Translation and Duplication has activated under "WPML > Settings → Media Translation", WPML indeed generates a new database entry for each translated image. As a result, a new ID gets assigned to the translated media item.

The translated Media gets generated after translating the post or page that contains an image.

Please check this documentation for more information: https://wpml.org/documentation/getting-started-guide/media-translation/#id5

If you don't want the WPML to create a new entry with a unique ID, you can disable the options under "WPML > Settings → Media Translation". By doing so, the image will not be copied to the translated page/post. You'll need to manually add an image for each translation.

I hope this explanation is clear to you. If you need further assistance, feel free to let me know. I will be happy to help.

Best regards,
Prosenjit

November 9, 2023 at 11:30 am #14765549

xavierC-7

Ok thank you for your answer, indeed regenerating image sizes in both languages did the trick.
A bit tedious though since it takes 7 hours for 5000 high-resolution images, for each language.

Is there a plugin you recommend that would regenerate and update the meta_data of all "language wise" images at once? It wastes ressources because the physical copies of images are regenerated twice.

November 10, 2023 at 4:43 am #14772217

Prosenjit Barman
WPML Supporter since 03/2023

Languages: English (English )

Timezone: Asia/Dhaka (GMT+06:00)

Hello There,
Thank you for the update.

I'm glad to hear that regenerating image sizes for both languages resolved the issue, although I understand the process is quite time-consuming with a large number of high-resolution images.

Currently, I can't recall any specific plugin that can generate metadata for all images at once. However, I can share a script that could be used to generate metadata for all the images in the media library. This script would automate the process, potentially saving you time and resources by handling the task in one go.

You can find the script here: hidden link

The process of using the script is described in the readme file. Please try accordingly and hopefully, it will help to generate Metadata for all the images in the media library. Before proceeding, make sure to take a full backup of the site and database.

Please let me know if that helps or if you need further assistance in this matter. I will be happy to help.

Best regards,
Prosenjit

November 10, 2023 at 9:05 am #14773627

xavierC-7

Thank you, you really provide great support.
I'll give a try to this php script if I have to change the image sizes again on this project.