Implements hook_url_outbound_alter().
Rewrite outbound URLs with language based prefixes.
function language_url_outbound_alter(&$path, &$options, $original_path) {
  // Only modify internal URLs.
  if (!$options['external'] && language_multilingual()) {
    static $drupal_static_fast;
    if (!isset($drupal_static_fast)) {
      $drupal_static_fast['callbacks'] =& drupal_static(__FUNCTION__);
    }
    $callbacks =& $drupal_static_fast['callbacks'];
    if (!isset($callbacks)) {
      $callbacks = array();
      include_once DRUPAL_ROOT . '/core/includes/language.inc';
      foreach (language_types_get_configurable() as $type) {
        // Get URL rewriter callbacks only from enabled language methods.
        $negotiation = variable_get("language_negotiation_{$type}", array());
        foreach ($negotiation as $method_id => $method) {
          if (isset($method['callbacks']['url_rewrite'])) {
            if (isset($method['file'])) {
              require_once DRUPAL_ROOT . '/' . $method['file'];
            }
            // Avoid duplicate callback entries.
            $callbacks[$method['callbacks']['url_rewrite']] = TRUE;
          }
        }
      }
      $callbacks = array_keys($callbacks);
    }
    // No language dependent path allowed in this mode.
    if (empty($callbacks)) {
      unset($options['language']);
      return;
    }
    foreach ($callbacks as $callback) {
      if (function_exists($callback)) {
        $callback($path, $options);
      }
    }
  }
}