diff --git a/pathologic.module b/pathologic.module
index 4e8147a..28deedf 100755
--- a/pathologic.module
+++ b/pathologic.module
@@ -113,10 +113,13 @@ function _pathologic($text, $filter) {
  * Replace the attributes. preg_replace_callback() callback.
  */
 function _pathologic_replace($matches, $absolute) {
+  global $language;
+
   // First, "files:" support. This is fairly easy.
   if ($matches[2] === 'files:') {
     return $matches[1] . '="' . file_create_url(file_build_uri(urldecode($matches[3]))) . '"';
   }
+
   // Build the full URL, then take it apart
   $parts = parse_url('http://example.com/' . urldecode($matches[3]));
   if ($parts['path'] === '/' || $parts['path'] === '//') {
@@ -149,17 +152,33 @@ function _pathologic_replace($matches, $absolute) {
     $qparts = NULL;
   }
 
-  $url = url(
-    $parts['path'],
-    array(
-      'query' => $qparts,
-      'fragment' => isset($parts['fragment']) ? $parts['fragment'] : NULL,
-      'absolute' => $absolute,
-    )
+  // Build common url() options.
+  $url_options = array(
+    'query' => $qparts,
+    'fragment' => isset($parts['fragment']) ? $parts['fragment'] : NULL,
+    'absolute' => $absolute,
+    // Newer versions of PHP treat all objects as references,
+    // so we have to clone objects we might modify.
+    'language' => clone($language),
   );
 
-  // $matches[1] will be the attribute; src, href, etc.
-  return "{$matches[1]}=\"{$url}\"";
+  // If it's a node, try to determine language by the node
+  if (preg_match('/node\/([0-9]+)$/', $parts['path'], $node_matches) && function_exists('i18n_node_get_lang')) {
+    $lang_code = i18n_node_get_lang($node_matches[1]);
+    $languages = language_list();
+    if (isset($languages[$lang_code])) {
+      $url_options['language'] = clone $languages[i18n_node_get_lang($node_matches[1])];
+    }
+  }
+
+  // Check if this is not a menu item. If yes, we want to try prevent translating the path.
+  // On multi-lingual sites, language_url_rewrite() will be called and may
+  // rewrite the link in ways we don't want: drupal.org/node/961618
+  if (!_menu_find_router_path($parts['path'])) {
+    $url_options['language']->prefix = '';
+  }
+
+  return $matches[1] . '="' . url($parts['path'], $url_options) . '"';
 }
 
 /**
