Skip Navigation

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

Problem:
The client wanted to know how WPML's automatic translation feature handles product featured and gallery images, specifically if it duplicates these images in the database, and how to prevent this to avoid bloating the

wp_posts

and

wp_postmeta

tables.

Solution:
We explained that WPML's "WPML Media Translation" module manages media duplication across translations. By default, WPML duplicates media entries for each language in the database but does not duplicate the actual image files. To prevent automatic media duplication:
1. Navigate to WPML -> Settings.
2. Scroll to the 'Media translation' section.
3. Uncheck the options shown in the provided screenshot and save the changes.

We also clarified that it's not possible to have a single image load in the translation without duplication unless custom coding is implemented. If the client needs a custom solution, we suggested hiring a certified developer experienced in customizing WPML from https://wpml.org/contractors/.

Please note that this solution might be outdated or not applicable to your case. If so, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the issue persists, please open a new support ticket at our support forum.

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 3 replies, has 2 voices.

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

Assisted by: Prosenjit Barman.

Author Posts
May 5, 2024 at 6:28 am #15593956

xiaoweiX

Hi,

If I turn on WPML's automatic translation, how will it treat product featured and gallery images? Will it automatically duplicate these images to different attachment records pointing to the same stored image URLs under wp-content/uploads/? If that's the case, is there a way to STOP the automatic translator from duplicating images and just use the ones attached to the product in the original language? Because if possible at all, we'd like not bloat the wp_posts and wp_postmeta tables. Duplicating lots of images will probably do that.

Thanks
Shawn

May 6, 2024 at 6:40 am #15595147

Prosenjit Barman
Supporter

Languages: English (English )

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

Hi Shawn,
Thanks for contacting WPML Support.

I understand what you're looking for. When you enable WPML's automatic translation feature, it generally treats media, including product featured and gallery images, in a specific way. WPML has a module called "WPML Media Translation" which manages how media is duplicated and used across translated content.

By default, WPML will duplicate media entries for each language. This means that for every image attached to a product in the original language, WPML will create a new attachment post in the database for each translation. However, it does not duplicate the actual image files in your `wp-content/uploads` directory. Instead, these new attachment posts just contain the language information and point to the existing image URLs. This method ensures that the same image file is reused across different languages, which helps in not bloating your server storage with duplicate image files.

However, this process does increase the number of entries in the `wp_posts` and `wp_postmeta` tables because each image will have its own post entry in the database for every language version, even though they link back to the same physical file.

To prevent WPML from automatically duplicating media for translations and just use the images attached to the product in the original language, you can configure the WPML Media Translation settings. Here's how you can do it:

1. Go to the WPML -> Settings.
2. Scroll down to the `Media translation` section. There should be options concerning how media is handled with translations.
3. Uncheck the options marked in this screenshot(hidden link) and save the changes.

I hope it will help. Please feel free to let me know if you need further assistance in this matter. I will be happy to help.

Best regards,
Prosenjit

May 6, 2024 at 1:19 pm #15597558

xiaoweiX

Hi,

Thanks for the comprehensive reply. I tried the settings in your screenshot and found a couple of issues.

1.

hidden link These options can not be unchecked, they got checked after clicking the apply button and refresh the page.

2.

hidden link If I keep this option open, doesn't that essentially keeps duplicating media records in database? Whenever I upload an image, WPML creates additional attachment records in wp_posts for each language for it immediately. Is my understanding correct? If so, what about old images which weren't previously made available in all languages, when a product is translated, will the translated version be able to use this old image?

3.

With this config: hidden link I translated a product with existing images - no new images were uploaded. The translated product appears to be missing featured & gallery images. hidden link

4.

I also did a couple of other tests. I changed the Media Post Type to be untranslatable first, translated a product, the translated product misses feature/gallery images. I changed the Media Post type to be fall back to original if translation is not available, translated a product, and the product misses featured / gallery images.

I wonder whether there IS a way to force translated products to just use the featured / gallery images from the original product - NO media records duplication at all.

May 7, 2024 at 5:56 am #15599856

Prosenjit Barman
Supporter

Languages: English (English )

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

Hi There,
Thank you for your detailed update.

1. The checkboxes that automatically recheck themselves are due to WPML ensuring that some default settings are enforced to maintain functionality.

2. Yes, your understanding is correct. When you have the option to duplicate media for translations enabled, WPML creates additional attachment records in wp_posts for each language immediately when a new image is uploaded. This does not affect old images unless they are used in a new translation after changing the setting. If you use an old image in a translated product, and that image was not previously duplicated for the language, it might not appear in the Translation unless you run the duplication process for old media.

3 & 4: With the settings you've described, it is expected that you won't see images in the translations if they are not configured to be duplicated. The configuration you have prevents the duplication of media, leading to the absence of images in the translated versions of the products because they rely on having their own media records for proper display and functionality.

Unfortunately, it's not possible to have a single image load in the translation without duplication unless you implement a custom coding solution. Alternatively, you can maintain the settings where images are not duplicated and manually assign the image in each translation as needed.

WPML ensures all parts of your product information, including images, are fully adaptable for each language. This means each image gets its own record in the database, allowing WPML to tailor its description and other details to different audiences. While it might seem like an extra step, this is actually what allows WPML to customize your product presentation for each market, ensuring that all information is accurate and culturally relevant. Directly using the original images without this process would limit WPML's ability to customize and potentially lead to technical issues with image display.

I hope you can understand. If you're considering a custom coding approach, you might want to hire a certified developer experienced in customizing the WPML plugin from here: https://wpml.org/contractors/.

If you have any more questions or need further clarification on any aspect of WPML, feel free to ask! I'm here to help.

Best regards,
Prosenjit

May 7, 2024 at 6:15 am #15599899

xiaoweiX

Thanks. I ended up using this code snippet to force translated products to re-use images in the English product which prevented WPML from duplicating tons of attachment rows in wp_posts:

// Force translated product to use images from original product
add_action('wp_insert_post', function ($post_ID, $post, $update) {
// Check if the post type is 'product' and it's being updated
if ($post->post_type === 'product' && $update) {
global $sitepress;
// Check if WPML is active
if (is_object($sitepress)) {
// Get the original product ID
$original_product_id = $sitepress->get_original_element_id($post->ID, 'product');
if (!empty($original_product_id)) {
// Get original product gallery
$original_product_gallery = get_post_meta($original_product_id, '_product_image_gallery', true);
// Update translated product gallery with original product's gallery
update_post_meta($post->ID, '_product_image_gallery', $original_product_gallery);
}
}
}
}, 10, 3);