add .html to custom post type with WPML

Aleluhia !

it was because $type don’t use WPML function

Here is the code that works perfectly with WPML and translated slug :

// .html pour les customs posts

function rewrite_rules($rules) {
    $new_rules = array();
    foreach (get_post_types() as $t)
    $new_rules[$t . '/(.+?)\.html$'] = 'index.php?post_type=" . $t . "&name=$matches[1]';
    return $new_rules + $rules;
}
add_action('rewrite_rules_array', 'rewrite_rules');

function custom_post_permalink ($post_link) {
    global $post;
    if ( $post ) {
        $type = get_post_type($post->ID);
        $slug = apply_filters( 'wpml_get_translated_slug',$type,$type,'');
        return home_url() . "https://wordpress.stackexchange.com/" . $slug . "https://wordpress.stackexchange.com/" . $post->post_name . '.html';
    }
}
add_filter('post_type_link', 'custom_post_permalink'); // for cpt post_type_link (rather than post_link)