I have a multilingual site (English, Swedish) that uses LinkIt (http://drupal.org/project/linkit) to create links in content. LinkIt produces URLs like "node/123". The idea is that then pathologic will transform them into the aliased URL.

Pathologic gets the alias correct, but does not add the /sv/ or /en/ which results in lots of redirects and 404 for the non-default language.

I have Drupals language detection configured to only use URL path prefix. I'm also using the standard node-translation method (all translations of a node have their own node-id), so Pathologic should be able to find the correct language.

Is there some configuration that I've missed? How do I get pathologic to add the language path prefix?

Comments

Garrett Albright’s picture

Multilingual sites have always been a problem point for Pathologic. Right now, it attempts to deal with it by just passing along the language code that gets sent to its filter function callback on to the url() function, the function which does the actual building of URLs. So one thing that may help to check is whether the node that contains the text you're trying to filter itself has a language assigned to it, and that the content you're trying to link to is of the same language.

Other than that, I'm not sure what to suggest. There are so many possible ways that Pathologic and multilingual sites can be configured that it's quite difficult to troubleshoot remotely.

Garrett Albright’s picture

After further research, I'm convinced there's a core bug which is causing the node's language to not be properly passed to input filter callbacks when run. I've filed this issue against core about it. We'll see if anything ever comes of it.

horol’s picture

Workaround for me is disable $url_params['language'] parameter. pathlogic.module, line: 322:

$url_params = array(
    'path' => $parts['path'],
    'options' => array(
      'query' => $parts['qparts'],
      'fragment' => isset($parts['fragment']) ? $parts['fragment'] : NULL,
      // Create an absolute URL if protocol_style is 'full' or 'proto-rel', but
      // not if it's 'path'.
      'absolute' => $settings['current_settings']['protocol_style'] !== 'path',
/*workaround 'language' => isset($settings['language_list'][$settings['langcode']]) ? $settings['language_list'][$settings['langcode']] : $settings['language_list'][LANGUAGE_NONE], */
      // A special parameter not actually used by url(), but we use it to see if
      // an alter hook implementation wants us to just pass through the original
      // URL.
      'use_original' => FALSE,
    ),

and now this part of code return correct path with language prefix. pathlogic.module, line 365:

  // Now for the url() call. Drumroll, please…
  //dpm($url_params);
  $url = url($url_params['path'], $url_params['options']);
  //$url = url($url_params['path']);
  //dpm($url);

Maybe, it will be helpful for someone.

regards,
martin

Garrett Albright’s picture

Status: Active » Fixed

As a workaround for the core bug, I've tweaked the code so that no language object is passed to the url() function unless Pathologic thinks the link is to a file, in which case it passes the LANGUAGE_NONE object so that the file path doesn't get a language prefix - sort of along the lines of what horol did above, but again, it shouldn't break image paths. This seemed to leave things in a workable state for my testing, but I'm not sure if it broke something else, given the myriad of ways that multilanguage sites can be configured. Marking as fixed now; please reopen if the problem is still happening for you, or if you think you've spotted a related bug.

IT-Cru’s picture

Following code snippet helps to prevent links to public files from language prefixing and use the original url link to files with pathologic 7.x-2.5.

function hook_pathologic_alter(&$url_params, $parts, $settings) {
  // use original path of links to public files and do not prefix them with language path
  $file_public_path = variable_get('file_public_path', 'sites/default/files');
  $file_public_path = str_replace("/", "\/", $file_public_path);
  if (preg_match('~^' . $file_public_path . '(\/.*)?$~', $url_params['path'])) {
    $url_params['options']['use_original'] = TRUE;
  }
}

I think this should be integrate into the pathologic module itself, because the public files path do not work with the language prefix (correct me if I'm wrong).

horol’s picture

sorry for a bit stupid question... where can I place this snippet?
when I place it (content of the snippet) to 'pathologic.api.php' into hook_pathologic_alter() function at the end, it doesn't work.

IT-Cru’s picture

Hello horol,

the hook_pathologic_alter() function is used to define a hook in your own module.

You have to create your own module for example horol_custom and place the snippet in your horol_custom.module file as horol_custom_pathologic_alter(). hook have to be replaced with your module name.

Create Drupal 7 modules: http://drupal.org/node/361112

If you need help with creating this little module, contact me.

Best regards
Steffen

Garrett Albright’s picture

That hook implementation should not be necessary, as Pathologic should already not be prefixing paths to existant files. If this bug is actually happening, please create a new issue with details. Thanks.

richsky’s picture

Version: 7.x-2.4 » 7.x-2.6
Issue tags: +pathologic, +linkit, +multillingual i18n

Using linkit and pathologic on a multilanguage site ends on having double prefixed links to node. /en/en/mynode

This patch solves the problem http://drupal.org/node/1793896

yan’s picture

Having the same problem as mentioned in #9, but the proposed patch doesn't help. In my case what happens is that absolute links in my html text to my own website (like http://example.com/de/whatsoever) are changed to http://example.com/de/de/whatsoever when the setting "Correct URLs with Pathologic" is enabled. I thought this might be related to the LinkIt issue but it seems not to.

Opening this again - or is that wrong? Oh, I notice I'm on 2.4...

Kojo Unsui’s picture

Using simplenews + htmlmail + pathologic on a multilanguage site ends also on having double prefixed links to node. as mentioned above /en/en/mynode ...

None of patches or code snippets above are useful. I got around that bug at the moment, rewriting the output of the links into the view blocks I call inside the newsletter, but this cannot be a sustainable solution.

Garrett Albright’s picture

All, "paths are prefixed with language code twice" and "paths are not prefixed with language code" are different problems. To that end, please follow this issue for the double-language-code problem, and please only post in this one of you're experiencing problems similar to the original poster of this issue (and don't forget to re-open the issue with the "Status" menu).

Automatically closed -- issue fixed for 2 weeks with no activity.