Skip Navigation

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

Problem:
The client had two issues: First, they were unsure if using

set_post_thumbnail

after linking posts as translations with

wpml_set_element_language_details

should also set the thumbnail for all translations. Second, they encountered unreliability with

wpml_translate_single_string

, where strings registered in the default language were not translating correctly.

Solution:
For the first issue, we explained that WPML provides an option to duplicate media for translations, which can be forced in WPML > Settings > Media Translation by clicking "Start". The hook wpml_apply_save_attachment_actions is responsible for media synchronization.

Regarding the difference between

wpml_translate_string

and

wpml_translate_single_string

, the former is used for string packages found at WPML > Packages, which help translate custom database tables, while the latter is for individual strings. For option strings, the hook wpml_unfiltered_admin_string is available.

For the second issue, we clarified that media synchronization options in WPML > Settings > Media Translation only affect new content. Existing content requires manual synchronization using the "Start" button. We also provided information on how WPML uses custom database tables to manage language connections and media entries, as detailed in the documentation WPML custom tables.

If the solution provided here is not relevant to your case, or if it's 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 you still need assistance, please open a new support ticket in 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 14 replies, has 2 voices.

Last updated by Andreas W. 1 year, 1 month ago.

Assisted by: Andreas W..

Author Posts
March 15, 2024 at 3:02 pm #15415056

davidR-15

I have a question about set_post_thumbnail in relation to wpml_set_element_language_details and a problem with wpml_translate_single_string

To start with the first question.
(Sorry, cannot get used to Shift+Enter acting as Send)

So, the question about set_post_thumbnail:

When I link two posts as translations of each other using wpml_set_element_language_details, should a call to `set_post_thumbnail` on the post in the original language not also set it as a thumbnail on all translations?

The other problem with wpml_translate_single_string is simply that it's not working reliably.
I am using wpml_register_single_string to register a string, and then I call wpml_translate_single_string with the same value (and having made certain a translation in the desired language exists) and it simply won't translate the string.

Could it be that re-registering the same value before calling wpml_translate_single_string creates a new instance of the value that is not yet translated?

Could it be that re-registering the same value before calling wpml_translate_single_string creates a new instance of the value that is not yet translated?

And what differs indeed is the language in which the string is originally registered

The strings that keep working are those registered in the site's secondary language, while those that do not work are those registered in the default language.

March 15, 2024 at 3:25 pm #15415145

davidR-15

Some additional context:

- for set_post_thumbnail:

I create a post programmatically and use wpml_set_element_language_details, I then create another post and link both using another call to wpml_set_element_language_details.

I then set media on the original post (which is always then present on all language versions) and set a post thumbnail on the original post too (which often is only set on the original post, but not on the translations).

- for wpml_translate_single_string:

I have an list of items with names in the original/default language. I loop through the items and register the strings.
I then, for each item, loop through all site languages and use wpml_translate_single_string. It always returns the original string and not the translation.

Bonus question: Could you briefly illustrate or explain the difference between wpml_translate_string and wpml_translate_single_string ? I don't seem to understand under which conditions one would prefer one to the other.

March 15, 2024 at 4:49 pm #15415461

Andreas W.
WPML Supporter since 12/2018

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

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

Once we translate the content WPML offers an option that allows you to duplicate the media.

This will create the media entries for the media inside the media library in all languages.

You can force the creation of those entries at WPML > Settings > Media Translation by clicking "Start".

The following hook is responsible for this synchronization:
https://wpml.org/wpml-hook/wpml_apply_save_attachment_actions/

The difference between "wpml_translate_string" and "wpml_translate_single_string" is that the second one is used for a single string while the first one is used for a string package.

String packages are found at WPML > Packages.

String Packages are used to translate custom database tables:
https://wpml.org/documentation/support/string-package-translation/
https://wpml.org/wpml-hook/wpml_translate_string/

For option strings, we offer the following hook:
https://wpml.org/wpml-hook/wpml_unfiltered_admin_string/

March 15, 2024 at 4:56 pm #15415484

davidR-15

Thanks Andreas,

The media "duplication" (honestly, the configuration options are very confusing) works fine, it's just the thumbnail (or featured image) which is not automatically duplicated to (or rather referenced from) the translations.

There doesn't seem to be a hook equivalent to https://wpml.org/wpml-hook/wpml_apply_save_attachment_actions/ for thumbnails, thus I'm assuming I need to manually set the thumbnail on each post that I create, even if one is set as a translation of another one?

As for the translate_string vs. translate_single_string question, I think I see what the difference is. This is to avoid having whole Gutenberg or sitebuilder blocks or even pages show up in page translation.

Any idea though why my string translation could not be working or what I could check for to debug it?

March 15, 2024 at 5:53 pm #15415815

Andreas W.
WPML Supporter since 12/2018

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

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

Please check WPML > Support > PHP and WPML > Support > WordPress about the currently used memory and the WP Memory Limit.

Also, make sure that all required PHP extensions are enabled.

WPML Minimum Requirements:
https://wpml.org/home/minimum-requirements/#:~:text=In%20order%20to%20run%2C%20WPML%20requires%20the%20following%3A,for%20using%20XLIFF%20files%20in%20WPML.%20Weitere%20Elemente

We can further offer a WPML test site, on which you can recreate the issue and we take a close look into it.

March 18, 2024 at 9:14 am #15419739

davidR-15

I have noticed today, that thumbnails that I set manually on a post are actually being stripped from translations when they're programmatically being updated or linked.

The memory limit on this site is indeed a little low, all dependencies however are installed.
Let me look at the memory limit and then get back to you on this. Would appreciate if we could keep this ticket open in the meantime.

March 18, 2024 at 1:55 pm #15421538

davidR-15

The memory limits are now both fine.
The behavior has, unfortunately not changed.

I have re-read the documentation available at https://wpml.org/documentation/getting-started-guide/media-translation/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore#id5, which, in regards to thumbnails/featured images states:

"Duplicate featured images for translations – duplicates newly uploaded featured image so that it can be translated"

As I've mentioned before, these three options are quite confusing and the documentation doesn't help.
My interpretation is the following:

- if left unchecked, the featured image set on the original post is also used for the translation (both posts link to the same attachment_id)
- if checked, the featured image set on the original copy is cloned and can be changed separately (both posts link to separate attachment_ids)

March 19, 2024 at 5:35 pm #15428086

Andreas W.
WPML Supporter since 12/2018

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

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

You have two options on each original content, which are by default both "checked":

Media attachments

- Duplicate uploaded media to translations
- Duplicate featured image to translations

If "unchecked" then the media by default will not be displayed on the translated content.

Could it be that you changed WPML > Settings > Post Type Translatio > Media to "Translatable - or display original content if a translation does not exist"?

If so, please take note that this setting is by default locked to use "Translatable - only show translated content" and we do not recommend changing this setting.

March 19, 2024 at 5:49 pm #15428185

davidR-15

> "Translatable - only show translated content"

This is still set and hasn't changed.

I can try this once with both "Duplicate media attachments for translations" and "Duplicate media attachments for translations" checked, but I'm afraid it will actually, physically duplicate media and then display media twice on a post where it should only appear once.

Could you please clarify:

- What is the difference between "When uploading media to the Media library, make it available in all languages" and "Duplicate media attachments for translations" ?
- When the "Duplicate…" checkboxes are checked what is actually duplicated? The media (physically on disk) or the attachment post type (in the database) only?

March 19, 2024 at 5:59 pm #15428226

Andreas W.
WPML Supporter since 12/2018

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

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

It is not the media file that is getting duplicated.

WPML refers to duplicating the database entry for the attachment. The duplicates will create an entry inside the media library for each language.

This means, that if you go inside the media library and switch the language inside the top admin bar, then you will have the same original file available in all languages.

If there is no entry in a specific language, then the original media file can not be displayed in such a second language.

"When uploading media to the Media library, make it available in all languages" should be activated, so that if you upload media directly to the media library, then WPML will create the DB entries needed to make the media available in all languages.

"Duplicate media attachments for translations" should be activated, which will create duplicates of media while translating content, on which the original media file was uploaded directly.

If you do not duplicate media, then the original media files are not supposed to show up on any translation.

Why you should disable the options?

Usually, this would only be advisable if you want to use completely different contents, layouts, and media and design per language while translating the contents with the WordPress Editor.

March 19, 2024 at 6:00 pm #15428272

davidR-15

I now checked "Duplicate featured images for translations" only. This seems to work for featured images indeed.
For media in general, I have not checked "Duplicate media attachments for translations", but they still show for me in both languages.

The function I'm using in my template is a simple "$photos = get_attached_media('image');"

March 19, 2024 at 6:04 pm #15428306

davidR-15

> "Duplicate media attachments for translations" should be activated, which will create duplicates of media while translating content, on which the original media file was uploaded directly.

So if I understand correctly, if, by the time I upload media, content (here, the parent post) is already translated, then the media would associate with both posts?

> If you do not duplicate media, then the original media files are not supposed to show up on any translation.

But they do 😉

See for example
- hidden link
- hidden link

At no point during the creation of these posts or the upload of the media was the "Duplicate media attachments for translations" checkbox checked.

March 19, 2024 at 6:12 pm #15428328

Andreas W.
WPML Supporter since 12/2018

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

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

If you go inside the media library, change the language inside the top admin bar to English, and see those images of your post there, then they were synced at some point.

You are expecting the media not to show up on translated content?

Can you recreate this with a new post?

The general options at WPML > Settings > Media Translation will only take effect for newly created content, not for existing content.

For existing content, you need to use the button "Start" to sync all media.

March 19, 2024 at 6:24 pm #15428383

davidR-15

Yes, I can see the same attachments in both languages, and no, I have not synced them manually.

I do want the images to show up in both languages… so that's good.

For now, I'm just seeking to understand the WPML configuration options and why it does what it does.

I talked to a few other WordPress devs, and none of them understood how these options actually work. They all just check some options and pray it does what they need.

I think we can close this ticket.

March 19, 2024 at 10:35 pm #15429092

Andreas W.
WPML Supporter since 12/2018

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

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

These options create entries on the database and we use custom database tables to create language connections.

https://wpml.org/documentation/support/wpml-tables/

As you can see, there are quite many custom WPML tables and this setup can be pretty complex.

WordPress saves attachments on the tables wp_posts (attachment) and wp_postmeta (_wp_attached_file).

On wp_postmeta for example you will find an option called "wpml_media_processed" which takes the post ID and the meta ID and this is then processed on our custom tables, to add language information.

The post attachment then gets written to the table wp_icl_translations where it will add our option values for IDs on this table we write the attachments once as original content.

Then, once the content is getting translated and media gets duplicated we include a new entry on wp_icl_translations for each translation of the attachment with its proper language code while pointing as well to the source language code.

This database information is then used to display images in different languages on wp-admin and the Frontend.