Skip Navigation

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

Problem:
The client is confused about the Media Translation options in WPML, specifically wanting to ensure that every language uses the same original language image file without duplicating the images physically for different languages. The client also wants to avoid creating new image files for each language translation.
Solution:
First, we recommend taking a backup of your site and database due to the nature of the solution involving direct database manipulation. Here are the steps to address your concerns:
1. Run the following MySQL Query to delete all translated media from your site:

DELETE from wp_icl_translations WHERE element_type="post_attachment";

2. Clean up the wp_posts table by executing this query:

DELETE from wp_postmeta WHERE meta_key="wpml_media_processed";

3. To prevent WPML from syncing the media again, navigate to WPML > Settings > Post Type Translation and set Media (attachment) to "Not translate".
Please note, this procedure is generally not recommended as WPML needs to sync media to display it in different languages, which is why such a feature was not provided initially.

If this solution does not apply to your case, or if it seems outdated, 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 further assistance is needed, please open a new support ticket at WPML 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.

This topic contains 12 replies, has 3 voices.

Last updated by The J 1 year ago.

Assisted by: Andreas W..

Author Posts
May 2, 2024 at 4:48 pm #15588534

The J

Even after years of using WPML, the Media Translation options are still confusing.

I would like to know exactly which options to use in the WPML settings, so that:

- every language uses the same original language image file
- no images are ever duplicated physically for different languages
- if a translation is duplicated from original language, then simply import in the translated content the same img ID

The attached screenshot is what makes sense to me, everything else seems like it creates a new image file for every language, which I dont want.

Can you please clarify this, both here and inside the WPML settings? because even reading the documentation, it is not clear at all what you mean with "Duplicate" (to me it means create a new copy of the same image.. so there are 2..3..4 copies on disk of the same image file, which I dont want)

Thank you

2024-05-02 18_31_13-Settings ‹ Flexalighting — WordPress.png
May 2, 2024 at 5:26 pm #15588616

Lauren
WPML Supporter since 10/2015

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

Thank you for contacting WPML support. While you are waiting for one of my colleagues to take this ticket and work on it, let me provide you with first debugging steps or if I can perhaps help with the issue quickly.

The most important thing to answer your question is that the term "duplicate" as it is used here does not refer to duplicating the actual image file. It means that the image meta will be duplicated in the database so that it can be used for the other languages.

The option you have selected in your screenshot means that when you create new content, if you upload media, it will be available for all languages to use. It will not, however, copy any media uploaded to a post to its translation, and it won't copy the featured image to the translation.

The best thing to do to use image from the original language for all other languages is to set all of the fields to duplicate. This creates the entry in the database (not the file on your server) so that it shows for all languages automatically. You will want to check the options to duplicate for translted content and click start to run the sync as well. I hope I have answered your question.

May 2, 2024 at 6:46 pm #15588842

The J

So the options should be like this?

And this wont' physically duplicate anything, but simply add to translations the same image ID for feat image and attachments ID of the main language?

So what happens if I dont select those options, and only leave " When uploading media to the Media library, make it available in all languages"?
If I dont slect those options, then simply if I clone a content, then feat image and attachments will be empty right? But I can still re-attach them from the same media files I uploaded through the main language content? or not...? are there others differences?

Finally, the 2 "duplicate" options above (unchecked) are simply to do the operation I just described above automatically, right?

Can you confirm that NONE of these options duplicate physically the images in the hard disk? but simply re-use the 1 single physical original image, in all translated content?

Final question: why the need to duplicate media entry in db, for translations? cant you use the same id as the main language? it seems like chaotic db management like this and hard to keep track over time... leading to bloated db tables.

2024-05-02 20_42_15-Settings ‹ Flexalighting — WordPress.png
May 4, 2024 at 3:20 pm #15593583

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

None of these options will create duplicated physical files on your server.

WPML only needs to create one entry for each image in each admin language inside the WordPress Media Library.

If you go to the Media Library switch the language inside the top admin bar and review the media count you will be able to verify how much of your media is already available in other languages.

If a media entry does not exist in a different admin language, then the images will not be able to show up on translated content.

The option WPML > Settings > Media Translation > Start will go through the whole media library and create missing language entries. The first checkboxes above this "Start" dialog refers to what WPML should do if you click "Start".

The option in the lower section refers only to how WPML should handle media for newly created content.

The synchronization of media is essential for media to be available on translated content.

Please let me know if you have any further doubts or questions.

Best regards
Andreas

May 7, 2024 at 3:32 am #15599602

The J

Thank you, it seems clearer now (maybe more info in the plugin settings itself would be helpful).

How do you suggest to do in case of needing to delete thousands of images, that are then "duplicated" in other languages?

Assume you want to bulk delete them all (in original language and any other language) - and obviously doing it by hand isn't an option.

May 7, 2024 at 4:12 pm #15603200

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

WPML needs to sync all media, if it does not, the media will only be available in the site's default language. The only thing WPML will create is database entries. It will not duplicate physical files.

If the option WPML > Settings > When deleting a post, delete translations as well is enabled, and you delete the original entry inside the media library, then the entries in other languages will be removed from the media library.

If you still need the original media but want to remove the media entries in another language and there are thousands affected, then we could only do this quickly by accessing the database directly and running a MySQL query.

I can offer to take a look into this for you if you take a complete backup of the site and database and provide me admin access.

Would you agree with that?

May 14, 2024 at 7:07 pm #15626818

The J

Makes sense, thank you.

Would you please share the SQL query to be able to delete ALL media translations, leaving the original language media IDs intact in the db?

Thank you

May 14, 2024 at 7:19 pm #15626828

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

I am sorry, but I can not provide such a query, as WPML saves the language information for the media on various tables, while the actual media is saved on WordPress's posts table and this table does not come with any language information.

Please proceed as follows:

- Create a backup of your website. You can use backup tools from WordPress: https://wordpress.org/plugins/tags/backup/

- Go to "WordPress Dashboard > Media > Library". Switch to list view.

- From the top admin bar change the language to the second language.

- Select all the media there and delete them.

Now you deleted all the database entries for that specific language.

May 14, 2024 at 7:22 pm #15626831

The J

That cannot be the only way WPML has planned to do this....
We are talking about 5000+ images, in some cases for 3-4 languages.... with hostings usually being able to take on max 150 images per bulk delete.
You are suggesting I do this manually 33 times per language.......?

May 14, 2024 at 8:02 pm #15626961

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

I am sorry, but this would be very complicated to handle with MySQL only - maybe not even possible - I would have no idea how to handle that and we have never received such a method as a solution from any developers or second tier. If we had such a query available on our support channel, I would provide it to you.

The reason why this is complicated:
WPML adds the language information by connecting the IDs of each post, page, taxonomy or attachment by adding language information on our own tables.

You could even remove all the custom tables generated by WPML, which would remove only all the language information, but the translations for posts, pages, attachments, menus, templates or taxonomies, will remain on your site and get assigned to site default language, as they are saved on WordPress's database tables and those tables do not have any language information.

Further, please take note that none of our supporters are supposed to provide any custom code solutions. If some supporters provide custom code solutions, then they do this on a voluntary basis, but such services are not covered by our support policy.

WPML Support Policy:
https://wpml.org/purchase/support-policy/

SOLUTION:
On the top right corner, the "Screen Options" tab allows you to set the display limit in WordPress.

You could use a value of 999 and delete your images in 5-6 steps.

May 14, 2024 at 8:43 pm #15627067

The J

I cant set it to 999, as I said, most hosting providers only allow about 150 before timing out on bulk delete... unless you have a super dedicated server that has enough resources to do that and you can set the php vars to custom values and a max exec time of 10 or 20 minutes.... (unrealistic on 99% of hosting solutions).

I understand support isnt required to provide "custom snippets", but I consider this as a fundamental need for a plugin that creates so many "ghost" entries in the db, not a "custom support" request.

The WPML plugin itself should have tools for advanced management like this, not requiring users to ask support staff so often for such ordinary maintenance tasks. As you said, WPML saves data in several db tables and they're not even connected to each other directly or explicitly... making things extremely difficult to manage sometimes.

A professional website will have thousands of translated contents/media, so while WPML is great at many things, creating or editing translations is only one part of the job of a good plugin... organizing all this data in the db in a precise way and managing tasks like bulk translations delete or orphan db rows cleanup and check, should be the other part of the job.

I'm saying this as a feedback to WPML in general, in over a decade I've had many clients moving away from WPML because they didnt want to deal anymore with the headache of bloated db rows or having to deal manually with such complicated/disjointed manual maintenance (which is common) and with no support for it.. as per your policy.

May 15, 2024 at 12:12 am #15627337

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

I totally understand your concerns and I ran a test now, to investigate and find a solution.

Actually, my theory about how WPML handles the duplicated media attachments was completely wrong, and I want to apologize for that.

You might need to adapt the table prefix on those queries according to the value used on your site. Please take a backup of your site and database. The usage of those queries is at your own risk.

The following MySQL Query will delete all the translated media from your site:

DELETE from wp_icl_translations WHERE element_type="post_attachment";

Further, you can clean up the wp_posts table by running those queries:

DELETE from wp_postmeta WHERE meta_key="wpml_media_processed";

Now, to prevent WPML will syncing the media again, set WPML > Settings > Post Type Translation > Media (attachment) to "Not translate".

Take note again, that this procedure is not recommended, as WPML will need to sync the media to be able to display media in different languages and this further must be the logical reason why our developers never considered providing a different solution on this matter,
as it is simply mandatory for WPML to create those DB entries.

May 15, 2024 at 4:06 pm #15631655

The J

Thank you Andreas for your help!!!
I will try these queries.

I understand the need for the media translation, but e.g. on dev sites when things are being tested (like for big imports) it's best to stay light at first, instead of having thousands of entries that need to be deleted every other day.

I really hope WPML takes this into consideration seriously for future versions (a way to easily get rid of all media/db rows in bulk, from wpml tools).

You can close this ticket 🙂