qTranslateX with featured image

Not infrequently it happens that for multilingual systems an additional featured image with picture text is needed. With the plugin Multiple Featured Images it is possible to extend qTranslateX to use featured images for different languages. In our example we use the languages German and English. Since the default language is English, we add a German image in the functions.php with the following code:

add_filter( 'kdmfi_featured_images', function( $featured_images ) {    
		$args = array(        
			'id' => 'featured-image-lang-en',        
			'descsc' => 'Beitragsbild EN',        
			'label_name' => 'Beitragsbild EN',        
			'label_set' => 'Beitragsbild EN festlegen',        
			'label_remove' => 'Beitragsbild EN entfernen',        
			'label_use' => 'Beitragsbild EN festlegen',        
			'post_type' => array( 'post' ),    
		);    
		$featured_images[] = $args;    
	return $featured_images;
});

Since it rarely happens that an additional German image is needed, the featured image should only be replaced if a German image is really present. The following additional code automatically exchanges the actual post image:

add_filter( 'get_post_metadata', 'wdm_change_featured_image', 10, 4 );
function wdm_change_featured_image( $feature_image_id = null, $post_id, $meta_key, $single ) {
    if ( $meta_key == '_thumbnail_id' ) {
         if(function_exists('qtranxf_getLanguage')) {
	      if (qtranxf_getLanguage() == 'en' && kdmfi_has_featured_image( 'featured-image-lang-en', $post_id )) {
	          $feature_image_id = kdmfi_get_featured_image_id( 'featured-image-lang-en', $post_id );
	      }
	  }
    }
  return $feature_image_id;
}