Skip Navigation

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.

Our wait time is higher than usual, please make sure you are meeting the minimum requirement - https://wpml.org/home/minimum-requirements before you report issues, and if you can take a look at current Known Issues - https://wpml.org/known-issues/. Thank you.
Sun Mon Tue Wed Thu Fri Sat
- - 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00
- - - - - - -

Supporter timezone: America/Lima (GMT-05:00)

This topic contains 19 replies, has 1 voice.

Last updated by Andreas W. 22 hours, 25 minutes ago.

Assisted by: Andreas W..

Author Posts
March 22, 2025 at 4:51 pm #16847837

alexZ-17

Background of the issue:
I am trying to translate AltTexts for images included through the WP-Carousel plugin on my site hidden link. When images are directly included, the AltText is available in normal Page translation.

Symptoms:
If the images are included through a carousel (WP-Carousel plugin), there is no place where I can translate the AltTexts - they are always shown in English.

Questions:
How can I translate AltTexts for images included through the WP-Carousel plugin?
Why are AltTexts not available for translation when using the WP-Carousel plugin?

March 22, 2025 at 8:51 pm #16847986

Andreas W.
Supporter

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

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

Hello,

The image meta information is not part of the WP Carousel.

In such case, you need to translate the meta information directly inside the media library while switching the admin language to the second language and editing the media.

If you do not find the media in a second language you will first need to run the dialog to sync media at WPML > Settings > Media Translation by clicking the "Start" button.

If this will not solve the issue, please let us know.

Best regards
Andreas

March 23, 2025 at 1:40 pm #16848707

alexZ-17

Hello,
Language changed to German;
Opened in Translation Editor;
Alternative Text inserted, updated;
Result: the text in the German page is still in English
regards

Alternative Text updated.jpg
Language changed to German.jpg
March 25, 2025 at 12:36 pm #16857577

Otto
Supporter

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

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

I apologize for the delay in answering. I will take care of this ticket and reply time will be shorter now.

To ensure the quickest and most accurate support, please provide your debug information so I can look at some of your configurations. We have an excellent article on how to locate it here: https://wpml.org/faq/provide-debug-information-faster-support/.

WP Carousel is not in our compatibility list, however, it doesn't necessarily imply that it is not compatible, just that our team has not tested it yet.

Which version are you using? Free or PRO? The author claims that the PRO version is compatible with WPML:
hidden link

I suggest checking with their support, too.

With your response, we will move forward.

Best Regards,
Otto

March 28, 2025 at 1:21 pm #16873135

alexZ-17

I use the free version
regards

March 28, 2025 at 1:25 pm #16873146

Otto
Supporter

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

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

You should check with them if the free version is compatible.

On our end, we have tested these alternatives for the carousel feature:
https://wpml.org/plugin-functionality/slider/

Best Regards,
Otto

March 28, 2025 at 1:29 pm #16873150

alexZ-17

have you checked the debug information provided by me?

March 28, 2025 at 1:35 pm #16873172

Otto
Supporter

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

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Yes, I did. I didn't note anything off there. It helps us to detect memory issues or outdated plugins, for example. But it looks OK in this case.

Best Regards,
Otto

March 28, 2025 at 2:00 pm #16873366

alexZ-17

I am dissapointed by your formal approach to my problem.
Would you be so kind to return the ticket to Andreas?

March 28, 2025 at 5:39 pm #16874210

Andreas W.
Supporter

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

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

I was able to replicate the issue on a test site.

General workflow:

The shortcode to display a WP Carousel looks like this:
[sp_wpcarousel id="30"]

This means that each carousel in each language has a unique shortcode.

You need to make the WP Carousel post type inside WPML's setting "Translatable", then translate the carousel and make sure that you use the correct shortcode on each page.

Go to WPML > Settings > Post Type Translation and set "All Carousels (sp_wp_carousel)" to "Translatable only show translated items".

Then go to WPML > Settings > Custom Field Translation and make sure that the following fields are set to "Copy":

sp_wpcp_shortcode_options
sp_wpcp_upload_options

Now go to WP Carousel > All Carousell and translate the carousel using the WPML Translation Editor. Back on the list, switch the admin language to German. You will now realize that the German carousel uses a different shortcode.

You might need to paste those shortcodes manually on each page.

Issue:
The now correctly translated WP Carousel will display the ALT attribute of its images in the site's default language.

Investigating this further, it looks like the WP Carousel post type is not getting the translations from the media library. Even if I try to edit the media information directly on the translated carousel inside the WordPress Editor, we still see the original meta information on the translated carousel.

The issue seems to be in how the carousel is being rendered on the Frontend.

To fix the issue, we will need the cooperation of the plugin's author.

Open the file

Replace the following function:

public static function get_item_image( $lazy_load_image, $wpcp_layout, $img_url, $title_attr, $width, $height, $alt_text, $lazy_img_url ) {
			if ( 'false' !== $lazy_load_image && 'carousel' === $wpcp_layout || 'slider' === $wpcp_layout ) {
				$image = sprintf( '<img class="wcp-lazy swiper-lazy" data-src="%1$s" src="%6$s" %2$s alt="%3$s" width="%4$s" height="%5$s">', $img_url, $title_attr, $alt_text, $width, $height, $lazy_img_url );
			} else {
				$image = sprintf( '<img class="skip-lazy" src="%1$s"%2$s alt="%3$s" width="%4$s" height="%5$s">', $img_url, $title_attr, $alt_text, $width, $height );
			}
			return $image;
		}

with this new function:

public static function get_item_image( $lazy_load_image, $wpcp_layout, $img_url, $title_attr, $width, $height, $alt_text, $lazy_img_url ) {
    // Use wpml_current_language filter to get the current language in WPML
    $current_language = apply_filters( 'wpml_current_language', null ); // Get current language

    // Ensure that WPML is active and the current language is set
    if ( class_exists( 'SitePress' ) && $current_language ) {
        // Get the attachment ID from the image URL (assuming $img_url is the image URL)
        $attachment_id = self::get_attachment_id_from_url( $img_url );

        if ( $attachment_id ) {
            // Get the translated alt text using the attachment ID
            $alt_text = self::get_translated_alt_text( $attachment_id, $current_language );
        }
    }

    // Construct the image tag depending on the layout and lazy load
    if ( 'false' !== $lazy_load_image && ( 'carousel' === $wpcp_layout || 'slider' === $wpcp_layout ) ) {
        // Lazy-loaded image
        $image = sprintf( 
            '<img class="wcp-lazy swiper-lazy" data-src="%1$s" src="%6$s" %2$s alt="%3$s" width="%4$s" height="%5$s">', 
            $img_url, $title_attr, $alt_text, $width, $height, $lazy_img_url 
        );
    } else {
        // Regular image without lazy loading
        $image = sprintf( 
            '<img class="skip-lazy" src="%1$s" %2$s alt="%3$s" width="%4$s" height="%5$s">', 
            $img_url, $title_attr, $alt_text, $width, $height 
        );
    }

    return $image;
}

// Method to retrieve translated alt text based on the attachment ID and current language
private static function get_translated_alt_text( $attachment_id, $current_language ) {
    // Ensure WPML is active and attachment ID exists
    if ( class_exists( 'SitePress' ) && $attachment_id ) {
        // Get the translated attachment using WPML's translation functionality
        $translated_attachment_id = apply_filters( 'wpml_object_id', $attachment_id, 'attachment', false, $current_language );

        // If a translated attachment is found, get the alt text from the translated post meta
        if ( $translated_attachment_id ) {
            // Get the translated alt text from the media attachment
            $translated_alt = get_post_meta( $translated_attachment_id, '_wp_attachment_image_alt', true );

            if ( $translated_alt ) {
                return $translated_alt; // Return the translated alt text
            }
        }
    }

    // Fallback to the original alt text if no translation is available
    return get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ); // Fallback to the original alt
}

// Helper function to get attachment ID from URL (example)
private static function get_attachment_id_from_url( $image_url ) {
    global $wpdb;
    // Retrieve the attachment ID from the image URL by querying the postmeta table
    $attachment_id = $wpdb->get_var( $wpdb->prepare(
        "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value LIKE %s",
        '%' . $wpdb->esc_like( basename( $image_url ) ) . '%'
    ) );

    return $attachment_id;
}

The old function was using $alt_text directly without linking it to a specific attachment ID.

WPML stores translations for media items based on the attachment ID. Since the img_url is the same across languages, there was no way for the function to fetch the correct translated alt text without considering the attachment ID.

The new function will make sure that we obtain the information for the correct attachment.

This solved the issue on my test.

I am now escalating this issue to our compatibility team, but please take note once more, that this problem will only be solved, if the author of WP Carousel adapts the code of the plugin to achieve compatibility with WPML.

March 29, 2025 at 7:00 am #16874917

alexZ-17

Thank you for the prompt reply.
Do I understand correctly:
1 The first way is to translate each carousel using the WPML Translation Editor under following settings:
WPML > Settings > Post Type Translation."All Carousels (sp_wp_carousel)" = "Translatable only show translated items".
WPML > Settings > Custom Field Translation.
sp_wpcp_shortcode_options ="Copy"
sp_wpcp_upload_options = "Copy"
2 The second way is to change a file - you do not mention the file name - by replacing a specific function.
Can I do it or the author of WP-Carousel should do this?
If I do it, does it mean that after every update of WP or the plugins - WPML and/or WP-Carousel - this replace should be repeated?
thx

March 29, 2025 at 2:02 pm #16875402

Andreas W.
Supporter

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

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

My apologies for forgetting to mention the file name.

The file is wp-content\plugins\wp-carousel-free\public\WPCF_Helper.php

I would suggest you report this to the author and ask if they would consider making the plugin compatible with WPML.

March 29, 2025 at 3:16 pm #16875461

alexZ-17

Ok, then I do the following:
1 I sent your proposal to ShapedPlugin Support with your code
2 Meanwhile I follow your workflow (in DEV) – cf. My ① in „Do I understand correctly:” above
3 If you consider your workflow to be too complicated or my qualification will be not sufficient
and ShapedPlugin is not eager to accept the replacement I may buy the professional version of WP-carousel ($139/ Lifetime)
I would highly appreciate your advice/approval.

March 29, 2025 at 3:40 pm #16875492

Andreas W.
Supporter

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

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

You can use the provided workaround and it will solve the issue.

If the author is willing to implement this change does sadly not depend on us.

It seems the PRO version supports WPML:
hidden link

Could you please ask them for confirmation?

March 29, 2025 at 4:17 pm #16875532

alexZ-17

Request to ShapedPlugin sent:
"
I refer to the problem AltText with WPML.
One of the best WPML supporters has found the reason of incompatibility and has provided a solution – replacement of one function in
wp-content\plugins\wp-carousel-free\public\WPCF_Helper.php
cf below.
I would appreciate if you could implement it.
"
follows your proposal ....