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

Last updated by Carlos Rojas 1 year ago.

Assigned support staff: Carlos Rojas.

Author Posts
September 11, 2018 at 1:28 pm #2723896

jakobS-7

I am trying to: Translate images alt, description etc.

But when i am on a translated post, all the image fields just shows blank when i try to edit.
The thumbnail shows the correct image, but nothing shows when i click edit.

I have tried Media Translation tool to duplicate all the image content to translations, but nothing happens.

I have posted screenshot as how the image details show on the correct language, and English language.

I have updated all plugins. Even tried the WPML Beta build, but without luck.

Any help is highly appreciated.

September 12, 2018 at 8:17 am #2726651

jakobS-7

This code seems to have fixed the issue.

But i wonder why this code in my functions file is necessary.
Can you explain if there is something i can do so i can avoid having this code in my functions file?

/**
 * Make Media attachments translatable with WPML
 *
 * Filter ACF images and galleries to switch attachment ids with their
 * corresponding WPML translation.
 */
add_filter( 'acf/load_value/type=gallery', 'my_acf_load_translated_attachment', 10, 3 );
add_filter( 'acf/load_value/type=image', 'my_acf_load_translated_attachment', 10, 3 );

function my_acf_load_translated_attachment($value, $post_id, $field) {
    $newValue = $value;

    // Make sure we are using WPML
    if ( function_exists('icl_object_id') ) {
        // Galleries come in arrays
        if ( is_array($value) ) {
            $newValue = array();
            foreach ($value as $key => $id) {
                $newValue[$key] = icl_object_id($id, 'attachment');
            }
        }
        // Single images arrive as simple values
        else {
            $newValue = icl_object_id($value, 'attachment');
        }
    }

    return $newValue;
}
September 12, 2018 at 10:45 pm #2729202

Carlos Rojas
Supporter

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

Timezone: America/Montevideo (GMT-03:00)

Hello,
Thank you for contacting WPML support.

Could you provide the source of the code added to the functions.php file?

Kind regards,
Carlos

September 13, 2018 at 7:08 am #2730272

jakobS-7

hidden link

September 13, 2018 at 3:04 pm #2732148

Carlos Rojas
Supporter

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

Timezone: America/Montevideo (GMT-03:00)

Hi there,
Thank you very much for providing this link.

I'm consulting our specialists about this issue. I will get back to you as soon as I have an answer.

Best regards,
Carlos

September 14, 2018 at 2:26 pm #2735709

Carlos Rojas
Supporter

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

Timezone: America/Montevideo (GMT-03:00)

Hi,

I have escalated this ticket to our development team where they are going to take a closer look at this code. I will get back to you as soon as I get an answer from them.

Thank you very much for your patience and understanding!
Best regards,
Carlos

September 30, 2018 at 2:13 pm #2776574

Carlos Rojas
Supporter

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

Timezone: America/Montevideo (GMT-03:00)

Hi there,

I would like to ask you to add this code to your functions.php file in your theme's folder:

/**
 * Make Media attachments translatable with WPML
 *
 * Filter ACF images and galleries to switch attachment ids with their
 * corresponding WPML translation.
 */
add_filter( 'acf/load_value/type=gallery', 'my_acf_load_translated_attachment', 10, 3 );
add_filter( 'acf/load_value/type=image', 'my_acf_load_translated_attachment', 10, 3 );

function my_acf_load_translated_attachment($value, $post_id, $field) {
    $newValue = $value;

    // Make sure we are using WPML
    if ( function_exists('icl_object_id') ) {
        // Galleries come in arrays
        if ( is_array($value) ) {
            $newValue = array();
            foreach ($value as $key => $id) {
                $newValue[$key] = icl_object_id($id, 'attachment');
            }
        }
        // Single images arrive as simple values
        else {
            $newValue = icl_object_id($value, 'attachment');
        }
    }

    return $newValue;
}

Could you tell me if the issue is solved?

Best regards,
Carlos