Jump to:
| Project: | Pathauto |
| Version: | 7.x-1.x-dev |
| Component: | I18n stuff |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
We have a great feature to allow different paths per language.
Main issue I have with that when you create English content, there is no French path. This means when viewing the site in French, that piece of English content has an old node/x path, not a French path. In some cases it even leads to a 404 page, because a specific path does not exist in French.
This is a problem for mixed content sites, where the Drupal interface may be switched languages, but the mixed language content and its paths should be accessible everywhere.
So this is the issue:
- create an english language node
- pathauto generates the english path
- problem: the french path is not generated.
This piece of content only gets an english path, not both.
In my case the solution seems to be changing all paths to 'und', which means they are available for All. my paths include the [nid] token aways, so I dont get duplicate paths anyway.
So in pathauto.inc before
// Save the path array.
path_save($path);I added an extra line
$path['language'] = LANGUAGE_NONE;To force neutral-language paths for whatever mixed language content. The idea is that a path should always be available in every site-language, regardless of the content language.
Comments
#1
So perhaps that should be a pathauto setting, "Force neutral paths: yes/no".
#2
Just implemented this...hoping that it works! Thank you for the suggestion. -catrina
#3
See also #1289550: Alias for all languages. This is not likely to be an option in Pathauto any time soon.
#4
@Dave Reid
Why so? Do you mean it goes against your vision of Pathauto or you just don't have a time to implement it?
#5
Never mind
#6
coming from: #1236030: interface language change the path of the node
#7
I support morningtimes idea - It works !
It must be simple to put a "yes/no" - for now it works, but can overwritten by a update...
#8
subscribe
#9
Visard, do you have the code? If so, could you please share it?
#10
morningtime, thank you! your solution works like a charm.
Would be nice too see the option in pathauto interface.
#11
I guess this is because it's now possible to do it using
hook_pathauto_alias_alter(), that hook is well documented and it actually includes the code for doing this.To be completely specific, the needed hook should look like this:
<?phpfunction yourcustommodule_pathauto_alias_alter(&$alias, array &$context) {
// Force all aliases to be saved as language neutral.
$context['language'] = LANGUAGE_NONE;
}
?>
So, since this is a support request, I guess it's safe to mark it fixed.
#12
what about interface option? otherwise we should be obliged to patch every time after any upgrade.
#13
In case someone is interested, I've created a tiny sandbox module for this. Upon enabling it resets all the existing paths to be language neutral and alters new ones as they're created.
http://drupal.org/sandbox/akamaus/1420990
#14
Automatically closed -- issue fixed for 2 weeks with no activity.
#15
I don't why we wouldn't add this in as a new feature? Sounds very useful to me.
One thing I am concerning is that if we have one alias for all language, and another alias for (e.g.) English. So, when the UI is in English, pathauto should try to use English alias first. But, the current code doesn't
#16
Another direction is that we don't throw 404 when the alias language doesn't match UI language (or make this an option)?
#17
not sure i exactly understand this but is this the same bug i am seeing?
i have a fr/en site but specific node type is not set to be translated. as a result i have only the one entry in pathauto patterns for this node type. this is all correct.
when i create a new node, the language for the entry in url_alias is EN. pretty sure this is wrong. it should be UND. but it sort of sounds like this fix described here is making ALL url_aliases UND; which can't be correct as some will be EN and some FR and some will be UND. if this is the same issue as reported here this is obviously a bug; so changing to bug; if my issue is something else; please let me know and flip back to feature request.
#18
one test i did:
- node type is translatable nodes
- node/103 | en-test | en
- node/104 | fr-test | fr
- when i go to node/103, url is correct
- when i hover over my custom language switcher to switch site to FR, the url is also correct (fra/fr-test)
if i now change both these entries to und, everything still works as it should
perhaps the language selector is more for nodes with translated fields. where there would be this:
- node/103 | en-test | en
- node/103 | fr-test | fr
that makes sense.
so what i am reporting is still a bug. non-translatable nodes should get und. plus i am also seeing another bug in pathauto (should make sep issue) is that i see entries for the same non-translatable node with one as EN and the other as UND. possibly node type switched from translatable to non? but when node was updated it should do a replace of the url alias entry; not add a new one (i.e. should never have UND and a language for same node).
#19
ok, after debugging this a little i see issue is from somewhere other than pathauto; perhaps i18n? the language of the non-translatable node is passed to pathauto with $node->language = 'en'; which is incorrect as it should be 'und'.
although as i think about this my guess would be this is more likely a core bug in how Drupal handles language in general. I am sure if i set the node type to be translatable and set the language specifically as lang neutral; then it will pass und (next test); but as Drupal bases everything by default in EN; my guess is if not explicitly set to neutral (which i can't do for this node type as it is not translatable) then it gets EN by default (which is wrong).
#20
and sure enough that works. so setting the node as translatable and saving the node as neutral lets pathauto do the right thing.. so my issue (which is maybe different than being discussed here) is likely more with i18n and/or core. ughhh!!
#21
just to close off on this; and extending from what marvil07 posted above; i think this is better:
function mycustommodule_pathauto_alias_alter(&$alias, array &$context) {if (!i18n_node_type_enabled($context['data']['node']->type)) {
$context['language'] = LANGUAGE_NONE;
}
}
although i still think a bug in core; but from what i heard at Drupalcon i think D8 will no longer have concept of a base language; so this is likely already fixed there.