You cannot do this by just adding a rewrite rule, you need to change every recorded rules.
Here is a simple way to do this:
function my_rewrite_rules($rules) {
$new_rules = array();
$new_rules['(?:de|en)/?$'] = 'index.php';
foreach ($rules as $key => $val) {
$key = '(?:de|en)/?' . $key;
$new_rules[$key] = $val;
}
return $new_rules;
}
add_filter('rewrite_rules_array', 'my_rewrite_rules', 11);
Now you still need a way to receipt the language value in order to save it in a cookie.
You could add a parameter for the language, in order to get it inside the $_GET
super global. But that would means to offset all other parameters of all other rules, and this would involve a lot of regex.
Instead you can simply get the language by querying the $_SERVER
global:
preg_match('/\/(de|en)(\/|$|\?|#)/', $_SERVER['REQUEST_URI'], $matches);