How to make pathalias generate alias for all languages?
Spaiz - October 15, 2008 - 23:12
| Project: | Pathauto |
| Version: | 6.x-1.x-dev |
| Component: | I18n stuff |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
I have russian translation of Drupal site which has english setup as a second language. Pathauto generates url aliases for special language, which isn't accessible from another language, how to make pathauto generate one alias for all languages? Just can't understand what to do with that.

#1
Can you provide some more specific examples? If you have one alias for all languages how do people access the right language?
#2
people dont need to access right language, because there is only one language - russian, english left as a secondary. SO there is no content in english. But half of content was created before localization (translation) another half after, so when I create node, for some content pathauto generates english version of alias, for some russian and for some (taxonomies for example) no language specified alias (language field is blank, what I actually need). So I want to make pathauto generate one alias not connected with any language (ALL or blank language field should be set in url_alias table)....how to do this?
#3
In that case set your default language to Russian and disable English?
#4
I think that might still cause issues with aliases being language specific, but it's a good first step to try. Please report back if nonsie's suggestion doesn't work out for you.
#5
Hi there, I can clarify on this a bit, as I stumbled upon the problem myself.
The core issue is that when Pathauto generates the url alias, it will set the language of the alias to be the language of the edited node.
(pathauto.module, line 245, nodeapi - update/insert)
$alias = pathauto_create_alias('node', $op, $placeholders, $src, $node->nid, $node->type, $node->language);
My problem was the following: during development, I did not install the Italian language. Once the development finished, I added Italian (interface translation, *not* content translation!), and suddently my paths stopped working. That's because all my nodes had English language (as they were created before Italian was introduced), and therefore all the aliases created by autopath were set as English. Once you set Italian as default language, auto-paths will stop work.
What I did, was (via phpmyadmin):
update path_url set language = ''
This brought all the paths back to "All languages", which is what I wanted, and they started working again.
Then I edited a node and saved it, and I discovered that, again, that particular path stopped working, That was because that node was still set to be English, and therefore when the path got re-created, it was re-set for English only.
So the final solution for me was to run:
update node set language = 'it';
update path_url set language = ''
New nodes created from now on have the language set to Italian, as it became the default for the website, so paths are created in Italian, and everything apparently works. Until we add another language ;-)
******************
What I'd suggest, is to add a switch to the Pathauto configuration, where you can choose among:
1. Set the path language to the node language (though I can't figure out the purpose of this, since you don't have multiple rules, one for each language. So what will happen is that when you edit the node in english, you will use the node rule, and generate the path in english, then when you edit the node in italian, you will still use the same rule, and you will generate an identical alias, only the lang will be different)
2. Don't set the path language (valid for all languages)
#6
Thanks for the explanation. I'm not sure that more controls in the admin area is a solution, but it's worth discussing.
#7
I use 6.3 stable. And have the same problem with paths. Most part of our content was migrated from previous site version (non Drupal). And alias language was set us ''. During one week site works under english and after that the default language became norwegian. Besides mentioned problems there is one more. New content can generate the same alias as is in database using norwegian language. Example: I've got in database alias with dst = '/page/my_page' and empty language field. When i add new page with the same name new alias appears in database with dst = '/page/my_page' and language = 'nb'. After that old content become unreachable by it's alias.
It would be nice to have any possibilities to make Drupal generate same alias for all languages.
#8
I think this is another side effect of #258785: Language for content types without language support must be Neutral
#9
I realize more options in the admin interface is probably a bad idea, given the number of options present already--but I would definitely appreciate a feature that disabled assigning url_aliases to a particular language. As is, I'm tempted to write some kind of hook that sets url_aliases to language = '' every time a node is updated or created.
Just as background: I'm attempting to build a site with an initial set of nodes in English, but with the option to translate the nodes into any installed language. I want the various contributed translations to be accessible via the Drupal language prefix, not a custom language-specific path.
For instance:
http://en.example.com/author/tom_clancyloads the English-language 'Tom Clancy' node andhttp://fr.example.com/author/tom_clancyloads the French-language 'Tom Clancy' node.Since pathauto wants to assign url_aliases to a language based on the node type, I wind up getting links like
http://fr.example.com/node/1234instead ofhttp://fr.example.com/author/tom_clancywhen I'm browsing the site in another language and the node has not yet been translated.#10
Hmm, upon digging into this a bit more (okay, 5 minutes more :P) I get the impression that this isn't what I want to do. I'm rather lost.
#11
In the case where i18n is configured to show "All content. No language conditions apply" it would be useful that pathauto generated language-neutral aliases. Otherwise some content will show up with "node/xxx" URLs.
#12
I experienced the same problem these days. Take a look at the support mailing list archives to have an idea. I support the idea of the two options for pathauto, to create a language specific url or to create a url that is the same for all languages.
#13
OK, here's a patch for the 2.x-dev series. It adds an option under the General Settings fieldset that displays all the languages set for the site and saves the default one used when creating new url aliases. It worked fine for me.
#14
Has anyone tried my patch submitted at comment #13?
#15
Hi.
After applying a patch I get an error on admin/build/path/pathauto.
You use
language_default()for the default value of the form element, but this isn't correct since the function returns an object of type stdClass and not a single string.Modifying the patch with the following snippet and it will work:
<?php$lang_default = language_default();
$form['general']['pathauto_lang_save'] = array(
'#type' => 'select',
'#title' => t('Default alias language'),
'#description' => t('When creating a new alias, set its language to this one.'),
'#default_value' => variable_get('pathauto_lang_save', $lang_default->language),
'#options' => $languages
);
?>
greetings,
Stefan
#16
Thanks for noticing this.
Here's the updated version (no need to create a new variable).
#17
This patch is great (I've been fighting with this issue of language dependent aliases for a while)!
I think an option "Same as node language" would be useful under "Default alias language", which keeps the current behaviour (the alias has the same language as the node, if it has any, or "all" for neutral nodes). Besides, it would be nice to have a similar drop-down choice in each node, or at least in each content type, to override the default behaviour.
Let me say, however, that an issue like the one mentioned in this thread should be solved in the core and a feature like the one implemented by the above patch would belong more naturally to the Path module, so that it could affect also manually generated aliases. But that is going off-topic…
#18
OK, I also had this problem, and I tried the patch in comment #16. The patch works, however, it universally make all aliase born with a single language, which bring troubles if you have a content type that already has different alias setting for differernt languages. I mean, the core function of pathauto allow you to set different alias for different languages for any content type that has enabled language support.
The common scenario is, you have both multi-language content type and non-language-support content type. For multi-language content type(s), the core function of pathauto is used; while for the non-language-support content type(s), the patch should be used while not interfering the alias settings for multi-language content types.
So, it would be better if this patch include a "if" so all multi-language content types will not be influenced by it.
#19
Hi Goofyx, hi everybody,
I updated the patch to apply the setting also to Bulk Update.
I would call this patch , it could even be a checkbox instead of a selection, what do you think about that?
I still have to test the whole thing when different aliases are used for content in different languages, I'll see if I can address the observation rised by michaelcrm in #18.
It would also be grat to hear from Pathauto devs, is there any hope to have this merged?
Regards,
Antonio
#20
Hi,
this new patch should address the issue raised by michaelcrm in comment #18.
Now language-specific patterns take precedence.
This makes me even more convinced that a list of languages is not the best way to present this option, a checkbox with a description like looks better. The description could be improved of course.
Ah, and as an extreme semplification, we could even decide that if a node type doesn't have a language specific pattern set, then aliases for All languages should be created, but it is a change of default behaviour so it could bring problems for users, but in this case a new option would not be needed at all.
Now I really would like to hear PathAuto dev's voice :)
Thanks,
Antonio
#21
Thanks ao2 for your contribution. My Drupal programming skills are rather basic, so I appreciate your contribution for enhancing my initial patch. :-)
Any comments from the Pathauto developer(s)?
#22
subscribing
#23
Hi,
here's an updated version of the patch, rebased against the latest stable release. Now the option is a checkbox, it is still in the General settings section, I can move it to Node settings if you find it more appropriate.
The title and description can still be improved.
Please report any problem with the patch. Ah, and remember to actually enable the setting, the old value is not used anymore.
Regards,
Antonio
#24
An updated version of the patch, with a better name for the stored variable, and some little improvements on the option description.
Ah, please remember to actually enable the setting (again, sorry), the old value is not used anymore.
Another note, if you use this patch consider also using the one in #541802: Let path_nodeapi reuse the current path alias language on update, sice without it the alias language will be resetted at every node update.
Regards,
Antonio
#25
This review is powered by Dreditor.
+++ pathauto/pathauto.admin.inc@@ -144,6 +144,15 @@
+ '#description' => t('Enable Language Neutral behaviour in alias creation for localized nodes. By enabling this setting, aliases for nodes <em>without language specific patterns</em> will be enabled for <strong>all languages</strong>.'),
^ Please don't uppercase the words. Write "Enable language neutral behaviour ...".
+++ pathauto/pathauto.module@@ -242,7 +242,17 @@
+ if ('' == variable_get('pathauto_'. 'node' .'_'. $node->type .'_'. $node->language .'_pattern', '')) {
^ Why do you concat simple strings rather than writing them into one string?
variable_get('pathauto_node_' . $node->type ...And string concatanation requires a spaces between
'and..+++ pathauto/pathauto_node.inc@@ -112,7 +112,17 @@
+ if ('' == variable_get('pathauto_'. 'node' .'_'. $node->type .'_'. $node->language .'_pattern', '')) {
^ Same as above.
#26
Thanks for review stBorchert, the new attached version fixes the style issue you reported.
Since I execute basically the same code every time
pathauto_create_alias('node', ...is called,I am thinking to move it inside
pathauto_create_alias(), the patch will be shorted and maybe it will have more chanches to be included?Regards,
Antonio
#27
Argh, I stumbled into this problem and it's really annoying problem to rectify.
Thank you Antonio for the fantastic patch, it seems to be working great - nice one.
#28
I've tried to apply this patch, but I still get node/xxx aliases. But not for all content, even though they should be similar.
I have understood that others have this problem when they are trying to use pathauto without any language prefix and with content which doesn't have any language chosen. That's my case, I have English and Finnish enabled, but now I'm trying to show everything in Finnish. I don't need to translate content, but it would be nice for my users to be able to change between languages and the interface would change accordingly. Pathauto just doesn't seem to make any aliases for my nodes, and when I click taxonomy terms, Drupal says that there aren't any nodes related to the terms, even though there are plenty.
#29
Thanx antonio, your patch works for me!
#30
Firstly, many thanks to Antonio and everyone else who has contributed to this patch. It was almost exactly what I needed, and I've tweaked it to make it exactly what I've needed.
Unlike in the use cases listed above, I'm working on a site that needs all aliases to be enabled for all languages, including aliases for nodes that have language-specific patterns. I've modified the patch to allow the user to choose from three options (using radio buttons, not checkboxes): default language handling (alias enabled for same language as node), alias enabled for all languages unless a language-specific pattern is set for said node, and alias enabled for all languages no matter what. I created the patch against pathauto 6.x-1.2 but it works equally well for 6.x-1.x-dev.
Any and all feedback would be appreciated; hope this helps others out there and moves the collective effort here forward. Wondering if the maintainers are considering incorporating this functionality into pathauto itself?
#31
Hi Jack,
I like your patch, it's all in the spirit of my little work, thanks. I haven't tested it yet, tho.
Two little comments.
Have you considered putting the language selection code directly in
pathauto_create_alias()? This would remove some duplication and should be more "submittable" in stable pathauto IMHO. I meant to do that, but never did so far.Please wrap lines in patch headers to a sane width :)
And a question: are you also using #541802: Let path_nodeapi reuse the current path alias language on update in your sites?
Ciao,
Antonio
#32
Hey Jack and ao2,
Thanks a lot for the patch it works great except for a duplication warning I receive every time:
* user warning: Duplicate entry 'content-' for key 'dst_language' query: INSERT INTO url_alias (src, dst, language) VALUES ('node/374', 'content', '') in C:\xampp\htdocs\drupal-6.14\modules\path\path.module on line 112.
* user warning: Duplicate entry 'content/feed-' for key 'dst_language' query: INSERT INTO url_alias (src, dst, language) VALUES ('node/374/feed', 'content/feed', '') in C:\xampp\htdocs\drupal-6.14\modules\path\path.module on line 112.
Any ideas how to fix this?
Thanks!
Nimi.
#33
@Nimi: which version of the patch are you using?
And can you tell us also your patterns for alias generation, it's better to exclude that the problem is there first.
Thanks,
Antonio
#34
ao2: I've installed the patch posted on comment #30.
I do not have a path alias set for nodes of type page. I think I may have misunderstood the purpose of this patch. Is it for creating one identical alias for two different languages (without the translating of the alias into the second language)?
For example:
I have two languages installed: hebrew and english.
When I create a new node in english pathauto creates an alias according to the node's title: example.com/hello
Then if I add a Hebrew translation, since the node's title is now in Hebrew, it ends up creating an alias in Hebrew: example.com/he/"Hebrew Characters"
So the patch I thought is supposed to create two aliases which are the same except for the prefix:
example.com/hello
example.com/he/hello
Is this correct? If not do you know how could I achieve this?
Thanks again,
Nimi.
#35
@jackaponte, your latest patch does not work for pathauto-6.x-1.2, although it applies cleanly.