Overview of the Issue
In Visual Composer, the caption and the alt text of images in the Single Image, Image Gallery, Image Masonry Gallery, Simple Image Slider and Feature Description elements are not sent to translation. The translated page shows them in the default language.
Workaround
Use one of these options:
- Instead of the Single Image element, add the image to a Text Block element, with its caption and alt text. The Text Block content is sent to translation, caption and alt text included.
- Or add this code to your theme’s functions.php file, then send the page to translation again. It sends the caption and alt text of the images in Visual Composer elements to the translation. We tested it with the Single Image element:
add_filter( 'wpml_tm_translation_job_data', function ( $package ) {
if ( empty( $package['contents']['field-vcv-pageContent-0']['data'] ) ) {
return $package;
}
$page = json_decode( rawurldecode( base64_decode( $package['contents']['field-vcv-pageContent-0']['data'] ) ), true );
foreach ( (array) ( $page['elements'] ?? [] ) as $element_id => $element ) {
foreach ( (array) $element as $attribute => $items ) {
if ( ! is_array( $items ) ) {
continue;
}
foreach ( $items as $index => $item ) {
foreach ( [ 'caption', 'alt' ] as $key ) {
if ( ! is_array( $item ) || empty( $item[ $key ] ) || ! is_string( $item[ $key ] ) ) {
continue;
}
$field = 'vcv-pageContentField--' . $element_id . '.' . $attribute . '.' . $index . '.' . $key;
$package['contents'][ 'field-' . $field . '-0' ] = [ 'translate' => 1, 'data' => base64_encode( $item[ $key ] ), 'format' => 'base64' ];
$package['contents'][ 'field-' . $field . '-0-name' ] = [ 'translate' => 0, 'data' => $field ];
$package['contents'][ 'field-' . $field . '-0-type' ] = [ 'translate' => 0, 'data' => 'custom_field' ];
}
}
}
}
return $package;
}, 10 );