WIP: WPML Media to put a different svg for each language

Hello,
I talk with WPML team and there is a bug between the feature “enable svg” from Bricks and WPML Media to put different image per language. As you can see when we use WPML Media to put a different svg for each language, it doesn’t work as you can see on my short recording that I made for you : WPML SVG Media translation.mp4 - Google Drive
It seems it doesn’t store the data.

We temporary solved it with this code

  • Open the /wp-content/themes/bricks/includes/integrations/wpml/wpml.php file.
  • Look for line 509.
  • Replace:
public function get_translated_attachment_id( $attachment_id ) {
    return apply_filters( 'wpml_object_id', $attachment_id, 'attachment', true );
}
  • With:
public function get_translated_attachment_id( $attachment_id ) {
    if ( is_admin() && did_action( 'admin_init' ) ){
        $current_screen = get_current_screen();
     }
 
    // Check if the current screen is the WPML Media Translation screen (you'll need the exact screen ID)
    if ( $current_screen && $current_screen->id === 'wpml_page_wpml-media' ) {
        return $attachment_id; // Return the original image if it's a WPML Media Translation screen.
    }       
 
    return apply_filters( 'wpml_object_id', $attachment_id, 'attachment', true );
}

Now, I can upload different svg in Media translation per language but it won’t work with svg widget to display translated svg, it only works if we put the svg in a image widget.

Greetings,

The WPML team offers me the following workaround for SVG widget:

Remember to take theme’s backup beforehand.

  • Open …/wp-content/themes/bricks/includes/elements/svg.php file.
  • Look for line 134.
  • Change:
$svg_path = get_attached_file( $this->settings['file']['id'] );
  • For:
$svg_path = get_attached_file( apply_filters( 'wpml_object_id', $this->settings['file']['id'], 'attachment', FALSE ) );

Hi @creativeart,

Thank you for reporting this. I was able to replicate it and have added this to our internal bug tracker.

1 Like

Do you know when this bug will be corrected ?

Hi @creativeart,

We’re unable to provide ETAs or specific timeframes for bug resolutions.

In Bricks Builder 1.12.4, my solution still working but now in the svg.php we need to replace

// Default: Get SVG from file ID
		if ( $source === 'file' && ! empty( $settings['file']['id'] ) ) {
			$svg_path = get_attached_file( $settings['file']['id'] );
			$svg      = $svg_path ? Helpers::file_get_contents( $svg_path ) : false;
		}

By this one

// Default: Get SVG from file ID
		if ( $source === 'file' && ! empty( $settings['file']['id'] ) ) {
			$svg_id = apply_filters( 'wpml_object_id', $settings['file']['id'], 'attachment', FALSE ); 
			$svg_path = get_attached_file( $svg_id ); 
			$svg = $svg_path ? Helpers::file_get_contents( $svg_path ) : false;
		}

I hope this bug will be solved one day.
You can see the code working on this website where we need to put different svg translation by language : Impactful cakes - Vegan, raw & radically responsible - Nats Rawline

Greetings,