Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
Converted pictures using EWWW image optimizer to png will get lost in second language
Solution:
Workaround from compsupp-6701

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.

Tagged: 

This topic contains 13 replies, has 2 voices.

Last updated by Stéphane 1 year, 8 months ago.

Assisted by: Ilyes.

Author Posts
March 22, 2023 at 11:19 pm #13309567

Stéphane

Tell us what you are trying to do?
We have a Woocommerce website -> Theme is Woodmart.
We need to treat the library, by converting PNG images to JPG.
To do that, I used EWWW, because it mentioned as a recommended plugin from WPML.
Before using it, EWWW confirmed that it work with WPML.

Is there any documentation that you are following?
I followed EWWW documentation

Important to know:
I'm not using WPML Media, so all images used are the same in both language

The problem:
On the main language, the image photo.png is converted to photo.jpg, and the images are loading fine.
On the other language, the image link in the html is still looking to image in PNG, so it doesn't load and create 404 errors.

What is the link to your site?
Not all the image are treated on our staging site right now, so, to view the problem, you have to refer to that page:
EN (default language):
hidden link
FR (second language):
hidden link

Capture d’écran, le 2023-03-22 à 19.16.36.png
Capture d’écran, le 2023-03-22 à 19.17.29.png
Capture d’écran, le 2023-03-22 à 19.15.51.png
March 23, 2023 at 9:39 am #13313309

Ilyes
Supporter

Languages: English (English ) French (Français )

Timezone: Pacific/Easter (GMT-05:00)

Hello Stéphane,

Both your theme “Woodmart” and plugin “Ewww Image Optimizer” are indeed listed as compatible with WPML.

In order to see if this issue is happening because of the configuration of your staging site, or just the combination of the EWWW Image Optimizer & WPML we need to isolate the issue.

I’ve created a sandbox here: hidden link

I’ve already configured WPML in 2 languages.

Please do the following:

Open the Sandbox link mentioned above
Download and activate the EWWW plugin you are using.
Create a basic page with some .PNG images and text in the default language.
Translate the page to French and save the changes.
Use the EWWW plugin to convert your .PNGs to .JPEGs.

Please note that we only need the theme/plugin and the related functionality, you don’t need to setup a entire website or clone your existing site.

https://wpml.org/faq/how-to-reproduce-issues-and-share-them-with-wpml-support/

Let me know when it is done.

Best regards,

March 23, 2023 at 1:41 pm #13315697

Stéphane

Hi Ilyes,

I followed your instructions, and here is exactly what I did:
- Installed Woodmart with its Child Theme, and imported the settings from our website.
- Installed and activated EWWW plugin, and copied the settings we have on the website
- Activated Woocommerce, because that's what we use.
- Activated WPML String Translation, just because it's activated on our website, but didn't touch settings.

Result:
Same problem as on our website: Images in the second language are still PNGs in the HTML, even thought for a reason I ignore, some image visually appear.

Here is some screenshots to show what I'm talking about.

Thanks in advance for helping with that issue.

Capture-d’écran,-le-2023-03-23-à-09.14.21.jpg
Capture-d’écran,-le-2023-03-23-à-09.12.46.jpg
Capture d’écran, le 2023-03-23 à 09.13.20.png
March 24, 2023 at 2:07 pm #13323933

Ilyes
Supporter

Languages: English (English ) French (Français )

Timezone: Pacific/Easter (GMT-05:00)

Hello,

Thank you for your patience, we had to test multiple scenarios,

I did 4 different environments with one specific picture (hidden link) and here are the results we got :

1- With Woocommerce and WPML : Uploaded .png product > translated it > Images are visible but we could see some traces of the .png link under the source code : hidden link

2- Without Woocommerce and with WPML : Created a new page with a .png picture > translated it > image is visible but again some traces of the .png link is seen under the source code : hidden link

3- With default Theme and WPML : Same result as previously

4- Only EWWW is active (no WPML, no WooCommerce and default theme): Created a new page with a .png picture > translated it > image is visible but again some traces of the .png link is seen under the source code : hidden link

Things to keep in mind:

I Tried these cases with different pictures, and got different results depending on the picture, sometimes EWWW just ignored the conversation (check this post : hidden link ) and some other times the .png trace didn’t exist (check this page: hidden link)
I couldn’t replicate the “404 failed to load resource” error in any scenario

Conclusion:
-> So far, It doesn’t seem related to Woocommerce nor WPML, it entirely depended on how EWWW reacts and converts a picture.

What can you do :

- You can try with several different pictures then you can see different the results and contact EWWW, they might be aware of this issue as suggested under their website here : hidden link

- They explicitly suggested that in some cases, it is more difficult to ensure that the database is updated with the new filename(s).

- And if you can provide us with a clear step by step to follow, to reproduce the issue as we have diverse results.

Please do not hesitate to contact us further if needed,

Thank you,

March 24, 2023 at 4:18 pm #13325243

Stéphane

Hi,

Thanks for those tests, but I think they don't reflect our reality, because we are using EWWW on already existing and translated products.

So, to really see the problem, here is what you should do:

1- Deactivate EWWW (because it as to be disabled when you'll create the product, and translate it too)
2- Create a product in EN with PNG images (Feature image + Gallery)
3- Translate the product in FR
4- Activate EWWW
5- Go to Media -> Bulk optimize -> Run the optimizer and wait until it finishes
6- Go to the product page in EN and verify that the image are showing (this will be the case)
7- Switch language to FR :
-> You'll see that there is a mix of PNG and JPG image links in the HTML code of the page. On my computer, I can see some of the image appearing (Probably because of the cache), but in fact, there are error 404 on images when you look from outside, like with Kproxy, as you can see here: hidden link

Another way to confirm the problem is by testing the page with GT Metrix: hidden link

(FYI, I did that test with Twenty Twenty theme, then we can see that the problem is between WPML & EWWW, and had nothing to do with Woodmart Theme)

In conclusion, it seems to be a dysfunction between WPML and EWWW.

Thanks to test it by yourself, and I'm sure you'll get the same result as me.

Then, I think it would be more logical that you talk with EWWW, as WPML recommends EWWW, and as EWWW told me it would work.

Thanks in advance.

March 27, 2023 at 2:11 pm #13339639

Ilyes
Supporter

Languages: English (English ) French (Français )

Timezone: Pacific/Easter (GMT-05:00)

Hello there,

Thank you for the details,

After further testing, I have escalated it to our developers.

We will be in contact with EWWW authors, but in the meantime, it may be useful if you talk to them directly as a client, they may already be aware of this issue.

I will update you once I receive feedback, also please feel free to check with me later on to see the status and I will be happy to let you know the status of this fix.

Your patience is appreciated and have a wonderful day,

Best regards,

March 27, 2023 at 9:57 pm #13343377

Stéphane

Hi Ilyes,

Thanks for letting me know what's happening ...

Concerning EWWW, I already had a long conversation with their support prior to trying their plugin, and they assured me that it was working for what I needed to do. So I think it's better to let your devs talk with their devs, and see if they find a way to make it work, which I hope considering the time energy I've put in that plugin.

Thanks in advance and I'll be waiting for news from you.

March 28, 2023 at 12:15 pm #13349093

Ilyes
Supporter

Languages: English (English ) French (Français )

Timezone: Pacific/Easter (GMT-05:00)

Hi,

Thank you for sharing these details and for your patience,

I’m keeping an eye on the status of your ticket, I will update you once I receive any feedback,

Your time and energy are appreciated,

Thank you

April 11, 2023 at 3:06 pm #13447685

Stéphane

Hi Ilyes,

any news from the Compatibility team ?

Thanks

April 11, 2023 at 3:45 pm #13447961

Ilyes
Supporter

Languages: English (English ) French (Français )

Timezone: Pacific/Easter (GMT-05:00)

Hello,

Thank you for your patience,

Actually, yes, I have recently received a solution to your issue.

It is related with the _wp_attachment_metadata post meta, we can use the wp_get_attachment_metadata to change the file format on front-end.

For this, please add the following code to your theme's functions.php file:

// WPML Workaround for compsupp-6701
function wpml_compsupp6701_fix_jpg_image_format( $data, $attachment_id ) {
    
	// Runs only if WPML is enabled
	if ( class_exists('Sitepress') ) {
		$image_url = wp_get_attachment_url( $attachment_id );
	
		$image_extension = strtolower( pathinfo( $image_url, PATHINFO_EXTENSION ) );
		$attachment_metadata_extension = strtolower( pathinfo( $data['file'], PATHINFO_EXTENSION ) );

		if ( $image_extension != $attachment_metadata_extension && $attachment_metadata_extension === 'png' ) {
			// Replace the extension with "jpg" in the file name
			$data['file'] = preg_replace( '/\.png$/i', '.jpg', $data['file'] );

			// Update the metadata for each image size
			foreach ( $data['sizes'] as &$size ) {
				$size['file'] = preg_replace( '/\.png$/i', '.jpg', $size['file'] );
			}
		}
	}	

    return $data;
}
add_filter( 'wp_get_attachment_metadata', 'wpml_compsupp6701_fix_jpg_image_format', 10, 2 );

This should fix the 404 errors on front-end and load the correct image format.

We will be also contacting the author of EWWW image optimizer plugin for a proper update.

Thank you again for your patience,

Best,

April 11, 2023 at 3:55 pm #13448005

Stéphane

Great news, thanks !

Just to be sure to understand how this code should make it work:

Do I need to re-run EWWW Optimizer to make the images appear, or I should just add that code and everything will be fine ?

Thanks in advance for this details.

April 11, 2023 at 4:20 pm #13448255

Stéphane

Forget my last message, I added the code and verified that it works without re-running EWWW, as the code just replaces the image extensions !

Thanks for your help.

April 11, 2023 at 4:38 pm #13448703

Ilyes
Supporter

Languages: English (English ) French (Français )

Timezone: Pacific/Easter (GMT-05:00)

Hello,

Thanks for the feedback,

I'm glad it worked for you, you can then set this ticket as resolved.

Have a great day,