Locale switching with a “language” taxonomy

You might be interested in url_to_postid function

Used as follows from your wpsx_redefine_locale function:

$url = $_SERVER['REQUEST_URI'];
$postid = url_to_postid( $url );

Note that this does not return the post id for custom post types but the function is located in /wp-includes/rewrite.php and might be extended if needed.

UPDATE: here’s your sample:

function my_function(){
if ( ! wp_is_post_revision( $post_id ) ){

    // unhook this function so it doesn't loop infinitely
    remove_action('save_post', 'my_function');

    // update the post, which calls save_post again
    $my_post_args = array();
    $my_post_args['ID'] = post_id;
    $p = get_post( $post_id );
    $lang_tax = 'my_lang_tax_name';
    $language_terms = get_post_terms( $post_id, $lang_tax );
    $my_post_args['post_name'] = $p->name . '_' . $language_terms[0]->slug;
    wp_update_post( $my_post_args );

    // re-hook this function
    add_action('save_post', 'my_function');
}
add_action('save_posts', 'my_function');

What have to be done further, but that’s up to you. You have to sanitize the situation when user changed language taxonomy term assigned to post, so you don’t get my-post_de_en instead of my-post_en on post which was before in de and had my-post_de slug. This would require some regular expressions stuff, but you’ll manage that 😉