Support

Account

Home Forums Backend Issues (wp-admin) Gallery field + WPML: image title is always shown in original language

Solving

Gallery field + WPML: image title is always shown in original language

  • The site is in 2 language.
    I created a slideshow with Gallery field. In backend: When I click on an image thumbnail it shown always the texts (title, caption, …) related to the original language (also if I switch the backend to translated language, and here is the problem).
    So, if I’m in translated-language backend and I change an image title it changes it for the original-language image and not for the translate-language image. Then, for that I need to go to Media section and change it there but it’s uncomfortable.

    ps. until now I haven’t done what I watch in this video https://vimeo.com/47708514#
    because all works great except for what I ask here

  • Hi, I’m having the same problem…

    Any update? Did someone find a solution?

    Thank you.

  • I think you need to tell ACF that it should load the value for the correct attachment translation.

    I just ran into the same problem and solved it with the following filter function added to functions.php. I have the the WPML Media Translation Module activated, but didn’t test it without it.

    
    /**
     * 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;
    }
    

    This isn’t tested thoroughly, but can you try if this is working for you?

    This might also fix the issue described in http://support.advancedcustomfields.com/forums/topic/wpml-and-gallery-field/.

  • Hey there,

    When you translate a post, all the custom field values are duplicated from one to the other.The gallery field in the english post contains the ID’s of selected images.
    When translated, the gallery field in the italian post contains the ID’s of the originally selected images.

    The issue here is that the ID’s are pointing to the english images, not the translated language images.This is due to missing logic between ACF and WPML.

    For now, you will need to remove the selected images in the gallery field and re-select them. This will ensure that the images selected are of the correct language – that way you can edit the titles correctly

    I hope that helps

  • The issue here is that the ID’s are pointing to the english images, not the translated language images.This is due to missing logic between ACF and WPML.

    Here is the missing logic: https://github.com/iamntz/acf-gallery-wpml-fix

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Gallery field + WPML: image title is always shown in original language’ is closed to new replies.