Foreign language node links are not aliased
jammer - December 27, 2007 - 05:07
| Project: | Drupal |
| Version: | 7.x-dev |
| Component: | path.module |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Desbeers |
| Status: | patch (code needs work) |
Description
- Create story with default language and assign path say /texts/one
- Use the translate button to translate it to different language
- Assign path to it say /texts/two
- Go to front page and the new translation properly links to /texts/one but the old one doesn't link to /texts/two but uses /node/2 instead
Don't know how hard this would be fix, but it's rather silly that they link differently.
Preferably would like to hide the node number and use the path url link instead.

#1
While Drupal 6 stores the path alias for nodes in the language you saved the node, when it emits a link to node/x, it does not know that it need to look up a path alias for that path in that language (and it should use the path or domain prefix for that language). This is a missing feature, and you can plug this in with contributed modules like i18n or localizer when they become available for Drupal 6.
#2
I don’t think this is a missing feature in Drupal 6, but a very serous bug.
Take the following scenario:
A site has English and Dutch content.
What happened:
What I was expecting:
Drupal should fallback to the most suitable alias, but it doesn’t. It looks for an alias in the active language and as only fallback it looks for a ‘non-language’ alias too....
Solution:
It looked to me that a contributed module can’t fill this gab because it’s a fundamental problem in function drupal_lookup_path() in path.inc.
Because path aliases are currently broken in HEAD and that issue is a bit out of my league so to say [1] I created a patch for Drupal 6 now.
What this patch does:
Function drupal_lookup_path() still likes the alias set for a specific language the most, but if it can’t find it, and we are looking for a ‘node/$nid’, it will take the first option it could find, whatever it has a language set yes or no.
Please note about this patch:
It will ignore aliases in ‘non-preferred’ language if the $path doesn’t contain ‘node/’. So you are still able to create an alias for ‘/contact’ in Dutch (‘kontakt’ as we call it) and in English it’s still ‘/contact’. It only became a bit smarter concerning ‘node’ aliases.
I set this issue to ‘critical’ and ‘code needs review’. I consider it critical because it’s breaking existing sites that upgrade to Drupal 6 and are using the (great) multi-languages capabilities and although the patch is not for Drupal 7, the solution is basically the same. The current alias-issues in HEAD are not related to this issue.
Nick
[1] path alias is broken in HEAD:
http://drupal.org/node/196862
http://drupal.org/node/222109
http://drupal.org/node/259412
#3
oops, wrong patch...
#4
Another patch; found a typo and tabs....
#5
I agree with Desbeers. This is rather unfortunate behaviour. Desbeers, if it's the same approach for 7.x, could you make a patch for that? There's no need to go about reviewing a 6.x patch when it won't be checked in until 7.x has been fixed...
Oh, and the patch from #4 introduces trailing white-space (new lines 74 and 89).
#6
It works for me.
and why Drupal 7?
#7
dvinegla: Because the (unwritten? written? (where?)) commit policy says that stuff needs to be committed to n.x before being applied to n-1.x before being applied to n-2.x before being applied to... (Where n is the version of HEAD.)
#8
As a heads up, patch #4 creates a problem I haven't been able to unravel as of yet with any pages that have the same alias in different languages. 1,2
Setup:
Issue after applying patch:
1Possible conflicts caveat #1.
2Possible conflicts caveat #2. This particular menu is a primary menu fed through a custom module similar to nice menus.
The issue seems to stem from the second part of path #4 when multiple rows from the query on line#89 causes $src to be set to the last row result at the end of the while loop.
Patching just the first part, the front pages are properly aliased, menu block shows up, and all subsequent links are aliased as outlined in the initial & #2 posts - I haven't found any other weirdness as of yet.
I'm still picking apart path.inc, patch #4, & where/if the above caveats cause a conflict; if I manage a fix I'll post it. In the meantime, thoughts or ideas from those that know the path & menu system better than I would be greatly welcomed.