I'm building a multilingual site in Drupal, with several custom content types. We use Link to allow editors to link to article abstracts, some of which are PDFs stored in sites/default/files. I'm running into a problem however where i18n is inserting an fr/ in front of relative link URLs.

Let's take a file called "test.pdf" as an example. The relative path to the file is:

sites/default/files/test.pdf

When viewing the French version of the site, this becomes:

fr/sites/default/files/test.pdf

This doesn't exist and returns a 404.

I realize this is the way that i18n works - but is there any way to disable the prefixing of fr/ on the link field? It seems as though it shouldn't be translating the path to the site's file directory...

Comments

mkelly’s picture

for now I've cheated and used a mod_rewrite rule to rewrite all paths that begin with fr/sites/default/files/ to sites/default/files ... but I still think that either i18n or the Link module should avoid translating any relative URL that leads to the Drupal files directory.

danmed’s picture

+1 for this one. I have encountered exactly the same problem today.

Another option is to enter the full URL, including the domain name (http://my.ste.com/sites/default/...) but in my case that will not do as we are preparing the site on a dev. server for later publication.

Please let me know if there's a solution to this.
thanks

danmed’s picture

+1 also. Came accross the very same thing lately.
i18n and CCK Link field are stable recommended version as of the date of this comment.
We use the Link field to allow editors to link to either external or internal resources, PDF, ... and have control over the name/text of the link (otherwise I'd have used CCK filefield + File Sources)
I resorted to entering the full url (http://...) but indeed that's not a solution. I may try the rewrite thing instead.
Very interested in any progress in this matter.

danielnolde’s picture

+1 - the same here.

Full url is not an option because content is entered in the pre-live-phase using a different domain name.

How/Where can the link/url be altered prevented to be prefixed with the language path?
Is there any discussion in the i18n module about this (i didn't find any)?

danielnolde’s picture

okay, this is not an i18n issue but a core issue – urls within the local public file system are falsely prefixed with a language url prefix.

There's a clean workaround for Drupal 7 (!) to prevent this, this is what i came up with - just make sure to replace MODULENAME with the name of a custom module you place this code into:

/**
 * Implementation of hook_url_outbound_alter
 *
 * Prevent language-path-prefixing of public file urls
 */
function MODULENAME_url_outbound_alter(&$path, &$options, $original_path) {
  $filebase = variable_get('file_public_path', conf_path() . '/files');
  // if path is part of local public files directory, mark link external ...
  // ... path has leading base_path (e.g. "/" slash)
  if (strpos($original_path, base_path().$filebase) === 0) {
    $options['external'] = TRUE;
  }
  // ... path has no slash or base_path => append it to make external link work
  else if (strpos($original_path, $filebase) === 0) {
    $path = base_path() . $path;
    $options['external'] = TRUE;
  }
}

(In Drupal 6 you can perhaps instead come up with a similar solution using custom_url_rewrite_outbound() placed in settings.php: http://deekayen.net/url-rewrite-override-drupal )

jcfiala’s picture

Status: Active » Closed (won't fix)

Thanks a lot, danielnolde.

Since this seems to be a core issue and not something we can help with, I'm going to close this ticket.