diff --git a/pathologic.module b/pathologic.module index bfa016b..06d01d6 100755 --- a/pathologic.module +++ b/pathologic.module @@ -127,6 +127,7 @@ function _pathologic_replace($matches) { // abuse eval() and friends; abuse globals; or abuse drupal_static(). The // latter is the least offensive, I think. $settings = drupal_static('_pathologic_filter'); + $langs = language_list(); // Now parse the URL $parts = parse_url($matches[2]); // Do some early tests to see if we should just give up now. @@ -176,6 +177,14 @@ function _pathologic_replace($matches) { else { $parts['trimmed_path'] = $parts['path']; } + // we want to remove the langcode prefix from the trimmed path if it already exists + // since it will be added by the language attribute + if (isset($langs[$settings['langcode']])) { + $lang_prefix = $langs[$settings['langcode']]->prefix . "/"; + if (strpos($parts['trimmed_path'], $lang_prefix) === 0) { + $parts['trimmed_path'] = drupal_substr($parts['trimmed_path'], drupal_strlen($lang_prefix)); + } + } if ($parts['trimmed_path'] === '') { // Okay, if we just ended up with an empty string, then what happened is // they linked to the front page of their Drupal installation using non- @@ -216,7 +225,6 @@ function _pathologic_replace($matches) { return $matches[0]; } // Okay, format the URL. - $langs = language_list(); $url = url( $parts['trimmed_path'], array(