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 4 voices.

Last updated by Andrey 2 months ago.

Assigned support staff: Andrey.

Author Posts
October 20, 2017 at 11:17 am #1406981

Julian

I am using Media Cloud (https://wordpress.org/plugins/ilab-media-tools/) to offload images to a cloud storage service for a WPML multi-lingual site.

When Media Cloud transfers already existing image files to cloud storage, it updates the WP media library entry for each image file with the new URL -- but *only for the currently selected language*. The corresponding records for other languages are not updated. These (other-language) records then have to be deleted, and then regenerated with the WPML Media translation module. They then have URLs pointing to the cloud storage.

When new images are added to the library, Media Cloud transfers the files and creates media library entries with URLs pointing to the cloud storage -- again, only for the currently selected language. WPML creates corresponding media library entries for all other registered languages, but with URLs that point to the WordPress server. These records then have to be deleted, and then regenerated with the WPML Media translation module, so that the URLs point to the cloud storage.

It would be very convenient if Media Cloud were better integrated with WPML, so that media library records for *all* languages were immediately given correct URLs.

I'm wondering if you would consider collaborating with the maker of Media Cloud to achieve that integration?

October 23, 2017 at 10:00 am #1408470

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hello, Julian.

Thank you for contacting the WPML support forum.

I could not test this issue on my server as this plugin requires an account with one of the cloud services which I do not have.
Nevertheless, when I check our internal documentation, I can see a ticket with what appears to be a similar case with another images cloud service, Cloudinary hidden link.
You can see the public forum ticket about the above here.
https://wpml.org/forums/topic/cloudinary-images-dont-translate-wrong-url/
Please, read the first post by the user in this ticket.
1. Are you getting similar results for the other languages (not default language) with the URL of the images as the user describes in his post?
If so then maybe the fix that is provided (and also helped that user) will also fix the issue with Media Cloud.
You can see this fix in this reply by Andres, my colleague.
https://wpml.org/forums/topic/cloudinary-images-dont-translate-wrong-url/page/3/#post-1289477
That code should go into the functions.php file of your theme.
Could you try it, please and tell me if it works for you?

We will be happy to cooperate with the Media Cloud authors in making their plugin officially compatible with WPML.
It would be great if you could contact the authors and urge them to join our Go Global Program.
You can find details about it here.
https://wpml.org/documentation/theme-compatibility/go-global-program/
If you have any contacts information of the authors (email), please share it with me, and I'll share it with our compatibility team so they will be able to contact them.

I look forward to your reply!

Thanks,
Itamar.

October 25, 2017 at 9:32 pm #1412107

Julian

Hello Itamar

Many thanks for your suggestion. The case with Cloudinary that you cite is somewhat similar but not quite the same.

Unlike Cloudinary, Media Cloud is not itself a cloud storage service, but enables the user to offload images in the WordPress media library to any of several such services (Amazon S3 and others, indeed any service with an S3 compatible API).

Perhaps I wasn’t entirely clear in my description – may I restate the problem?

Suppose there are a number of images already in the WordPress media library, with entries both in the default language and in other-language translations (created by the WPML Media Translation module).

Media Cloud will copy the image files from the WordPress server to the chosen cloud storage, and update the URLs in the WP media library – for the default language only. The media library entries for the other languages still have (valid) URLs pointing to the WP server. (In the Cloudinary case, as I understand it, these other-language entries had invalid URLs at this point.) One work-around is to delete these other-language entries from the media library, and then regenerate them with the WPML Media Translation module, after which they will have URLs pointing to the cloud storage.

When new images are added to the WordPress media library, Media Cloud will copy the image file to the cloud storage and place the (cloud) URL in the media library entry – again, for the default language only. The WPML Media Translation module also creates copies of the library entries for the other languages, but with (valid, i.e. working) URLs pointing to the WordPress server. Again, deleting these and regenerating them with the Media Translation module produces library entries with URLs pointing to the cloud storage.

Basically, Media Cloud is unaware of WPML, and ignores all media library entries for languages other than the default.

Nevertheless, I tried the fix you suggested (https://wpml.org/forums/topic/cloudinary-images-dont-translate-wrong-url/page/3/#post-1289477) but without effect.

The only contact info I can find for the author of Media Cloud is a twitter feed: hidden link

Thanks.
Julian

October 29, 2017 at 2:13 pm #1415015

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi, Julian.

I'm sorry for the late response here and thank you for trying the fix that I had suggested and for adding more information on this issue.

I'm discussing this issue with our second tier, and if needed I'll escalate this issue to our compatibility team to see if they can come up with a fix to it.

I'll keep you updated here.

Thanks,
Itamar.

October 30, 2017 at 3:28 pm #1415875

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi, Julian.

I've escalated this issue to our compatibility team.
They will check if a fix for this problem can be achieved and try to contact the authors of the plugin for cooperation with them.

I'll keep you updated here on any news from out compatibility team.

Thank you for patience.
Itamar.

October 31, 2017 at 1:34 am #1416289

Julian

Hi Itamar

Many thanks. I look forward to hearing of any developments.

Julian

November 25, 2017 at 3:58 pm #1441340

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kiev (GMT+03:00)

Hello Julian,

This is Andrey here from the 2nd tier support.

Can you please test a workaround below till we add the changes to the WPML Media plugin itself?

The code needs to be added to the functions.php file of your theme.

add_filter( 'wp_get_attachment_metadata', 'fix_attachment_metadata', 1, 2 );
function fix_attachment_metadata( $data, $post_id ) {
    if ( ! isset( $data['s3'] ) ) {
        $trid = apply_filters( 'wpml_element_trid', null, $post_id, 'post_attachment' );
        $translations = apply_filters( 'wpml_get_element_translations', null, $trid, 'post_attachment' );
        foreach ( $translations as $language => $translation ) {
            if ( $translation->original ) {
                remove_filter( 'wp_get_attachment_metadata', 'fix_attachment_metadata', 1 );
                $original_data = wp_get_attachment_metadata( $translation->element_id );
        if ( isset( $original_data['s3'] ) ) {
            $data['s3'] = $original_data['s3'];
        }
                add_filter( 'wp_get_attachment_metadata', 'fix_attachment_metadata', 1, 2 );
            }
        }
    }
    return $data;
}

Make sure to take a full backup of your site before you proceed.

Let me know how it goes.

November 29, 2017 at 11:36 pm #1445325

Julian

Hello Andrey

Many thanks for the suggested workaround.

I have tested it with two storage services (Amazon S3 and Sirv), and the results look good.

I have five active languages – English and four others. When running the Media Cloud upload utility with English selected as the current language, the few media library entries in other languages which have no corresponding English entry do not get updated with the cloud URL (which is understandable and predictable). Re-running the upload utility with each of the other languages in turn selected as current language processes these “orphans”.

Adding new images works perfectly – the WPML Media plugin creates entries for all non-currently-selected languages, and these entries have URLs pointing to the cloud storage.

Not good having to edit the theme’s functions.php – I look forward to seeing this integrated into the WPML Media plugin. Any indication of when that might be?

Thanks again.
Julian

November 30, 2017 at 9:06 am #1445511

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kiev (GMT+03:00)

Hello Julian,

Thank you for your feedback! I can not give you an estimated date yet but your ticket in our records. I will update you here once I have more news on this.

December 1, 2017 at 12:10 pm #1446883

Julian

Great, thanks!

August 14, 2019 at 3:51 pm #4396497

katieD-4

Hello,

Thanks for the fix above. I was having the same problem and the suggested code does fix it, unless the uploaded file is an SVG.

If it is, then the S3 URL only works in the language that the SVG was originally uploaded to. For any other languages, that same SVG reverts back to using the internal WordPress uploads path, e.g.

uploads/2019/08/filename.svg

.

I've been trying to debug the code above and if I log out

$original_data = wp_get_attachment_metadata($translation->element_id);

I get the attachment data from the original SVG, but it never contains the s3 array keys as it does for any JPGs, or PNGs etc.

I have installed Safe SVG (https://wordpress.org/plugins/safe-svg/) to allow SVG Upload into WordPress. I have the latest versions of WPML Media, WPML Multilingual CMS, WPML String Translation, and WPML Translation Management installed.

Do you have any idea how I could get WordPress to pick up the S3 data for SVGs that have been translated?

Thanks in advance 🙂

August 15, 2019 at 9:11 am #4399823

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kiev (GMT+03:00)

Hello Julian,

This should be already integrated with the latest WPML plugins.

@katied-4, this ticket is going to be closed. If this directly related to WPML plugins, you are welcome to open a new ticket detailing the issue. We'll help you as much as we can. Thanks.

August 15, 2019 at 12:54 pm #4400867

Julian

Hello Andrey

That's good news. When you say "the lastest WPML plugins", does that mean the latest production release, or an upcoming new release?

By the way, with the workaround you provided earlier, rather than editing the theme’s functions.php, it also worked by placing the function in /wp-content/mu-plugins/ (sorry, should have posted this before!).

Thanks
Julian

August 15, 2019 at 2:26 pm #4401581

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kiev (GMT+03:00)

Thanks for your feedback. It should be working with the latest production release.