Adding URL prefix for foreign language support

Are you sure you have correct regex? Also you shouldn’t use flush_rewrite_rules() on init hook. Better to just go and re-save permalinks options in admin, so you won’t flush rules every time.

Try to change regex to all chars, otherwise it looks good.

add_rewrite_rule ('^([^/]*)/?', 'index.php?lang=$matches[1]', 'top');

UPDATE:

and then you need to add parameter to allowed query vars

function custom_rewrite_basic_query_vars( $query_vars ){
    $query_vars[] = 'lang';
    return $query_vars;
}
add_filter( 'query_vars', 'custom_rewrite_basic_query_vars' );

in theme you can then work with query like this

$lang = urldecode(get_query_var('lang'));