Support from Acquia helps fund testing for Drupal Acquia logo

Comments

greggles’s picture

Status: Active » Postponed (maintainer needs more info)

Can you provide some more specific examples? If you have one alias for all languages how do people access the right language?

timonweb’s picture

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?

nonsie’s picture

In that case set your default language to Russian and disable English?

Freso’s picture

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.

palantir’s picture

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)

greggles’s picture

Component: Code » I18n stuff
Category: support » feature
Status: Postponed (maintainer needs more info) » Active

Thanks for the explanation. I'm not sure that more controls in the admin area is a solution, but it's worth discussing.

grafsl’s picture

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.

dvinegla’s picture

irritableshade’s picture

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_clancy loads the English-language 'Tom Clancy' node and http://fr.example.com/author/tom_clancy loads 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/1234 instead of http://fr.example.com/author/tom_clancy when I'm browsing the site in another language and the node has not yet been translated.

irritableshade’s picture

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.

kennu’s picture

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.

GoofyX’s picture

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.

GoofyX’s picture

Status: Active » Needs review
FileSize
1.68 KB

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.

GoofyX’s picture

Has anyone tried my patch submitted at comment #13?

stBorchert’s picture

Status: Needs review » Needs work

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

GoofyX’s picture

Status: Needs work » Needs review
FileSize
1.69 KB

Thanks for noticing this.

Here's the updated version (no need to create a new variable).

lifepillar’s picture

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…

michaelcrm’s picture

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.

ao2’s picture

FileSize
2.94 KB

Hi Goofyx, hi everybody,

I updated the patch to apply the setting also to Bulk Update.
I would call this patch enable Language Neutral behaviour in alias creation for localized nodes, 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

ao2’s picture

FileSize
3.24 KB

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 enable Language Neutral behaviour in alias creation for localized nodes without language-specific pattern 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

GoofyX’s picture

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)?

micheleannj’s picture

subscribing

ao2’s picture

Version: 7.x-1.x-dev » 6.x-1.1
FileSize
3.42 KB

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

ao2’s picture

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

stBorchert’s picture

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.

ao2’s picture

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

halfiranian’s picture

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.

mErilainen’s picture

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.

laxmankasula’s picture

Thanx antonio, your patch works for me!

jackalope’s picture

Version: 6.x-1.1 » 6.x-1.x-dev
FileSize
6.95 KB

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?

ao2’s picture

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

nimi’s picture

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.

ao2’s picture

@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

nimi’s picture

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.

GoofyX’s picture

@jackaponte, your latest patch does not work for pathauto-6.x-1.2, although it applies cleanly.

ao2’s picture

Version: 6.x-1.x-dev » 6.x-1.2
FileSize
3.13 KB

Hi,

I am cleaning up the patch hoping it can be eventually included in next pathauto version, the attached one is almost identical to the one in #30 but much much cleaner.

Can you please test it? This is going to be the base for the final version.

Changes from the patch in #30:

  • Moved all the logic into pathauto_create_alias(), this removed all the code duplication we had before.
  • Not handling feed aliases anymore, as the patch is about nodes for now, we need to discuss if we want to apply its logic to all pathauto sub-modules (node, feed, etc.)

TODOs:

  • Decide if this patch is only about 'node' module or not, this will affect the name of the variable we use in the code.
  • Cleanup the code, two conditions can be merged into one.
  • Review the strings in the admin UI.

Pathauto devs? Ping.

Regards,
Antonio

vatavale’s picture

subscribe

xarbot’s picture

Hello:
One question. Which version of the module must be installed for applying the patch in #36 ?

Thanks in advanced

Xarbot

ao2’s picture

@xarbot, the patch in 36 is for 6.x-1.2 stable version.

Once we agree on the approach to take I'll rebase and retest it on the development snapshot for the final inclusion.

Dave Reid’s picture

Issue tags: +bulk

Tagging all the bulk alias issues for #713238: RFC: Pathauto Bulk module.

Dave Reid’s picture

Status: Needs review » Needs work

As per #36 marking as needs work.

GoofyX’s picture

FileSize
2.45 KB

Here's an updated version of the patch as taken from comment #36 for the latest stable 1.3 version of Pathauto.

throk’s picture

subscribe

ao2’s picture

Title: How to make pathalias generate alias for all languages? » How to make pathalias enable alias for all languages?
Version: 6.x-1.2 » 6.x-1.3
FileSize
2.7 KB

@GoofyX: thanks.

Here's some further cleanup, changes since patch in #36/#42:

  • Merged the two conditions into one
  • Little cleanup to the Description field in the admin form

I am using this very patch on ao2.it and no problems so far.

TODO:

  • Decide if we want to extend the logic to all modules and not only to nodes, I am doing some tests about this.
  • Check admin form strings: please can some native English speaker help here?
  • Get feedback about #541802: Let path_nodeapi reuse the current path alias language on update: if users of this patch are applying that one too, please comment on that issue to speed up discussion about its integration into core.

We are getting close to an acceptable state to mark this "for review", please help that happen.

Thanks,
Antonio

gagarine’s picture

I try the patch #44 with success thanks.

# Decide if we want to extend the logic to all modules and not only to nodes, I am doing some tests about this.
Can we imagine having this options in general settings and also in all type with:
- Same as general
- Default language handling (each alias will be enabled for the language of
its node),

- aliases for nodes without language-specific patterns will be enabled for
all languages,

- or aliases for all nodes (including those with language-specific patterns)
will be enabled for all languages.

Or do you think is useless and disturbing for the end user?

Robin van Emden’s picture

Thanks for the patch! Just what the doctor ordered. Also applied #541802: Let path_nodeapi reuse the current path alias language on update , together save me from a lot of problems.

zbb’s picture

Hi all,

I'm having basically the same question as nimi in #34 http://drupal.org/node/321848#comment-2220818 .

How can I have pathauto create just THE SAME alias for each language the content is in? Which IMHO is different from what this patch does.

What I want:
welcome node/1 English edit delete
welcome node/2 German edit delete

(this is how my hand-edited aliases show up in the admin/build/path page.)

Vs. what pathauto does after the patch:
welcome node/1 All edit delete
willkommen node/2 All edit delete

Vs. what pathauto did before the patch:
welcome node/1 English edit delete
willkommen node/2 German edit delete

My intuitive feeling is that there should be a replacement pattern in the node path settings ( admin/build/path/pathauto ) for this.

Right now I am using [menupath-raw] and there should maybe be something like

[menupath-language-neutral-raw] or [menupath-default-language-raw].

Any ideas?

blueblade’s picture

Hi,

Can someone please tell me how exactly you can apply patch #44. I tried using netbeans but I can only get it add the patch for pathauto.orig/pathauto.inc file...the other one stay ignored...Is it safe to do this by hand?

Thanks.

gagarine’s picture

On netbean applied the patch on folder of pathauto. Trey are also some documentations on the web to howto applied a patch.

blueblade’s picture

Hi,

I have just applied patch #44 but am still getting urls like the following (for content language set to english):

user/1/story/123
ja/user/1/node/123 (I want this to be ja/user/1/story/123 instead)

Is there anything else that needs to be done after applying the patch? I tried also patching
#541802: Let path_nodeapi reuse the current path alias language on update as said by Robin van Emden but did not see any difference.

Also, I added under "Pattern for all Story paths in Japanese" on admin/build/path/pathauto page:

[language]/user/[author-uid]/story/[nid]

but that doesnt seem to help at all either...

can someone please help?

BB

Freso’s picture

@ blueblade:
The language of the alias is saved when updating the alias, so applying the patch won't change the saved language of already existing aliases. Did you try creating new story nodes after having applied the patch? Did they still retain the old behaviour?

blueblade’s picture

Hi Freso,

Thanks for your reply. Yes, I did resave the nodes, even created new ones for testing but I still get the URLs as node/[nid] instead of content-type-name-i-want/[nid] (here is the link to the patches I used: http://drupal.org/node/755464#comment-2779208)

I also tried another patch on this page for the latest dev version (see http://drupal.org/node/357185#comment-2796212) but didnt really get what I wanted...which patch should I go with?

Thanks again for your help.

BB

pfx’s picture

hi
I apply th patch #44 on pathauto 6.x-1.3
I select "Aliases for nodes without language-specific patterns will be enabled for all languages."
I delete old Alias for the nodes with multiples translations.
I reedit and resave that nodes for regenerate alias...
and it work fine for me alias are use as path for translated node.
big thanks

blueblade’s picture

hi pfx,

did you get drupal to show the right URL when a content is saved in one language then viewed in another language using the language switcher? or just to work correctly when you have the content save in all languages?

mnlund’s picture

Big thanks!

+1 for this...

pfx’s picture

hi blueblade,
I do not use language switcher on our school site mainly in French. Language teachers just need to publish sometimes articles in several languages. you can see an example here

ao2’s picture

@blueblade, I use the language switcher (preserve language) only to change the "Interface language", and I theme some tabs into the node to switch content translations, similar to the example from @pfx, just with tabs instead of plain links.

Regards,
Antonio

blueblade’s picture

Hi and thanks to pfx and ao2.

ao2,

Did you get the URLs to show correctly when switching the languages?

In my case, when a node is saved in language A, the URL will be shown as set in Pathauto, but when switched to different language, the URL will be shown as node/[nid] only. For example, when a Story node is saved in English, the URL when viewed in English interface is "story/123" but when the language is changed to Japanese, the URL will be "node/123" instead of ja/story/123". Please let me know if this is how it works for you. Thanks again.

BB

pfx’s picture

Hi ao2
I noticed a strange bug in my use.
1) I create content in French the language by default in my drupal. Pathauto generates the alias correctly independent of the language (in the path table it puts language = All).
2) then I create the English translation of this content. Pathauto generates the alias correctly (in the path table it puts language = All).
3) But if I edit again the English translation for some changes and I save it again, now Pathauto regenerates alias wrong (in the path table it put language = english instead of all)

Is anyone able to reproduce this failure? in my case I do not use the language switcher.

regards

GoofyX’s picture

Yes, I confirm this behavior. Even if you simply create a new node (the alias created is for all languages), and then edit it, then the alias is updated and is for the node's language (eg. English). You must then update the alias to apply for all languages.

ao2’s picture

@blueblade: I've never seen this, just for reference I:

  • set the prefix also for the default language (en in my case)
  • use content negotiation "Prefix with fallback" (if my memory serves me rightly)
  • never use language prefixes in pathauto patterns
  • use preserve_language instead of the native language switcher

I hope this helps you to have a working setup like in my case.

@pfx,@GoofyX: are you also using the patch from #541802: Let path_nodeapi reuse the current path alias language on update, this is needed so that the alias language is preserved on node edit.

Regards,
Antonio

Edit: I was linking this very issue instead of #541802: Let path_nodeapi reuse the current path alias language on update

blueblade’s picture

Hi ao2,

Thanks for your help. Can you confirm if I will need to install the patch #321848: How to make pathalias enable alias for all languages? Thanks again.

BB

ao2’s picture

@blueblade, sorry in #61 I meant #541802: Let path_nodeapi reuse the current path alias language on update this is needed in order to keep the alias language on node edit, maybe now your problem... _yet_ :)

pfx’s picture

Hi ao2,
Ok, I apply the patch #541802 and everything works fine now, language="all" for the alias is preserved during the update of content.
Big thanks

[ Note I had to manually apply this patch to drupal 6.16:
pfx@pfx-laptop:~/drupal-6/modules/path$ patch -p0 < path_nodeapi_update_dont_override_current_language-d6.patch
patching file modules/path/path.module
Hunk #1 FAILED at 162.
1 out of 1 hunk FAILED -- saving rejects to file modules/path/path.module.rej ]

Anonymous’s picture

Pardon my ignorance, but could this be made into a 'module', so that WHEN we upgrade our Pathauto to the next stable version and IF this functionality hasn't been accepted into Pathauto or Core, we won't have to re-do everything.

Also I wonder how this patch is different from this module: http://drupal.org/project/path_alias_xt

marvil07’s picture

@ao2: Thanks for the patch at #44, it works great!

To avoid forgetting about this I write it here: It would be great to have tests for this feature, since it's really hard to test manually, like blueblade mentioned and specified at #41 in #357185: template base_path() code - breaking il8n menu links

zualas’s picture

Thank you for the patch, it works great and solves a big part of the problem.

One issue that doesn't look fixed is that even though the aliases are now preserved for all nodes when switching the language, there is still no prefix on the url of the node.

For example:
node alias: content/review/review-35 (the content is in English)
when we switch the language to Russian, it will get the correct alias ru/content/review/review-35
but if we see a hyperlink for this node on a page, it will still be content/review/review-35, regardless of the selected language.

Does anyone experience the same problem?

Thanks!

ao2’s picture

@zualas: did you set the path prefix in the English language setup?

See admin/settings/language/edit/en, the default language has a null prefix by default but it can be changed.

Regards,
Antonio

zualas’s picture

Hi Antonio,

I tried setting the path prefix for the default language, but the problem stays the same:

Even though switching the languages preserves the correct links, if you see the node link somewhere on the page (for example, admin/content/node) , all nodes will still have a language-specific hyperlink.
If one user has created a node in Russian, and then another user has come to the site through the English menu, when he sees the link to that node, it will point him to ru/. So, even though the english user would like to go to en/, he will be pointed to the Russian one ru/. (then he can change the language back to English, but this step is not justified).

I hope i made it more clear this time.

Thanks!

risca’s picture

The same for me. It hasn't worked at all.

Please have a look at this patch: is the only solution that I have found (and works)

NaX’s picture

Firstly I am not sure if this is the correct issue, there seams to be a few long standing issues discussing very similar language stuff.

I have not tried any of the patches mentioned here.

To recap my problem (let me know if I am in the wrong place)

Nodes were their is no language for the currently viewed language, the link then falls back to the default language but the paths are not aliased.
EG: fr/node/123.

And their is no way of view nodes by alias regardless of the sites current language.

So what I tried to achieve is to be able to view any node by its alias via any language.
EG:
node/123 = about-us (English)
fr/en/about-us = node/123 (English path with the language set to French)

or
node/543 = fr/contact-us
fr/ru/contact-us = node/543 (Russian path being viewed on French site)

I hope that all makes sense.

I think I have been able to achieve this using the url_alter module and setting my own custom URL rewriting code on admin/settings/url-alter

I have never used custom_url_rewrite_inbound() or custom_url_rewrite_outbound() before and I really battled to get outbound to work.

I think this could be useful to some of the issues discussed in this thread and I would really like it if somebody could tell me what method would be best and if maybe I would be better off with one of the other patches mentioned.

It would also be nice if somebody a little smarter than me could review and test my method.

The code is sort of based on subpath_alias() and could easily be turned in to a contrib module with a dependency on url_alter.

The only problem I can see with this method is the default language. EG: I cant do this if English is the default language en/fr/about-us because the default language has no language prefix.

I hope somebody finds this useful and can provide some feedback.

FYI: I had some problems with JS errors when trying to upload these files.

NaX’s picture

I have abandoned my method described on #71 in favor of the patch on #44. My method mostly worked but had some small bugs and I did not like the added overhead.

I am also using the core patch mentioned, as I understand it is sort of required or patch #44 works best with it. (http://drupal.org/node/541802)

I understand what the pathauto patch is doing and I like how it works, but I don’t fully understand the core patch and what it impacts. When I have more time I hope to learn the logic. My current understanding of the core patch is that it prevents pathauto from matching the correct language on update. I also don't understand which of the 3 options the core patch impacts on if not all of them. I don’t think it impacts on the default option.

I have also upgraded to use the latest dev version as I see that other language related patch also got committed.

There was a call for review of the strings used for the settings form. I think each of the language options are fine. I would only suggest a more detailed description maybe with examples, as this setting does have a large impact on the sites alias handling.

My suggestion would be something along the lines of:

Configure how to handle aliases language. The default option will create alias that are language specific and only require being unique for that language and will only be used if matched to the current page language being displayed. When the default option is used and a language specific alias is not found links will fallback to using node system paths EG: node/123. The all language options will create aliases that are not language specific and can be accessed from any language. The all language options require aliases to be unique across the site.

It's a little long winded but you get the idea.
Somebody that knows better would need to check the logic I describe is correct.

Thanks for the patch.

GoofyX’s picture

Pathauto-1.5 was released yesterday. We probably need an updated patch for this version.

Is there a chance this patch finally makes it to the core of pathauto?

jackalope’s picture

The patch from #44 still works, albeit with patch making some offset adjustments. So the old patch still works, though an updated patch certainly wouldn't hurt.

ao2’s picture

Hi, I'd say to leave the patch in #44 untouched as long as it applies with no problems, a refreshed one can make some confusion in the discussion.

I am going to install drupal 7 beta1 in order to see if the change in #541802: Let path_nodeapi reuse the current path alias language on update is needed there as well, so we can go on with merging these two patches.

Regards,
Antonio

MichaelP’s picture

Dave Reid’s picture

Status: Needs work » Closed (won't fix)

We don't support multiple aliases for the same path in Pathauto.

NaX’s picture

@Dave Reid
I find it a little odd you are dismissing this issue. If path auto can't assist with this problem on multi-language sites do you know of an alternative.

cainrus’s picture

about #44 patch:
if you want to setup aliases for site with links like these for each language:

  • example.com/about
  • example.ru/about
  • example.eu/about
  • You will notice that only one alias generated correctly,
    And all other aliases have unique names:

    • example.com/about
    • example.ru/about-0
    • example.eu/about-1

    You can allow the work to this patch, only for materials with the language of Default (like English).
    Then users will be able to see the same links on all materials:

    • example.com/about - alias for all languages(English in defaule)
    • example.ru/about - alias for russian version
    • example.eu/about - alias for euro version

    For this to work as I described - you need to change the corrections of #44 patch:

    in pathauto.admin.inc:
    after:

        $form['general']['pathauto_node_enable_alias_for_all_languages'] = array(
          '#type' => 'radios',
          '#title' => t('Language handling for aliases of localized nodes'),
          '#default_value' => variable_get('pathauto_node_enable_alias_for_all_languages', 'default_handling'),
          '#options' => $lang_alias_options,
          '#description' => t('Configure how to handle aliases language.'),
        );
    

    just add these, and you will be able to configure patch:

    /*fix*/
        $form['general']['pathauto_node_enable_alias_for_not_default_language'] = array(
          '#type' => 'checkbox',
          '#title' => t('Only default language will have alias for all languages'),
          '#default_value' => variable_get('pathauto_node_enable_alias_for_not_default_language', FALSE),
          '#description' => t('All not default language aliases will have own aliases.')
        );
    /*end fix*/
    

    Then, in pathauto.inc:
    on these line:

    // If the alias already exists, generate a new, hopefully unique, variant
    if (_pathauto_alias_exists($alias, $source, $language)) {
    

    make changes:

    // If the alias already exists, generate a new, hopefully unique, variant
    if (_pathauto_alias_exists($alias, $source, $language)  && /*fix*/!$handle_only_not_default_lang_aliases/*end fix*/) {
    

    and find these code:

    if ($module == 'node') {
        $alias_for_all_languages = variable_get('pathauto_node_enable_alias_for_all_languages', 'default_handling');
        $lang_pattern = trim(variable_get('pathauto_'. $module .'_'. $type .'_'. $language .'_pattern', ''));
    
        if ((empty($lang_pattern) && $alias_for_all_languages == 'no_lang_pattern_all_langs') ||
            $alias_for_all_languages == 'all_aliases_all_langs') {
          $language = '';
        }
      }
    

    replace these code with:

      /*fix*/
      $handle_only_not_default_lang_aliases = variable_get('pathauto_node_enable_alias_for_not_default_language', FALSE);
      if ($module == 'node') {
        $alias_for_all_languages = variable_get('pathauto_node_enable_alias_for_all_languages', 'default_handling');
        $lang_pattern = trim(variable_get('pathauto_'. $module .'_'. $type .'_'. $language .'_pattern', ''));
        
        if ((empty($lang_pattern) && $alias_for_all_languages == 'no_lang_pattern_all_langs') ||
            $alias_for_all_languages == 'all_aliases_all_langs') {
          // only default language will be common
          $default_language = variable_get('language_default', '')->language;
          if ($handle_only_not_default_lang_aliases && strtolower($language) == strtolower($default_language)) {
            $language = '';
          }
        }
      }
    /*end fix*/
    

    All work fine for me now.
    And i have same links for all materials in my site.
    I think it will work for site with subdomains like en.example.com, de.example.com, ru.example.com too.

    P.s. my pathauto module version is 6.x-2.0-alpha3

    cainrus’s picture

    Status: Closed (won't fix) » Needs review
    Issue tags: -bulk

    I believe that the use of a reworked patch will expand the boundaries of pathauto

    Status: Needs review » Needs work

    The last submitted patch, pathauto_generate_aliases_for_all_languages-321848-44.patch, failed testing.

    klonos’s picture

    ...of course it will fail. Now the test bot runs all tests against d7.

    Dave Reid’s picture

    Status: Needs work » Closed (won't fix)

    No, we're pretty agreed between the maintainers that Pathauto should expand on it's current one-alias-per-URL stance. Feel free to keep communicating in this issue or try to work on a sub-module as a separate project, and if we need to make minor modifications to Pathauto in order to support the separate project, file a new issue. Otherwise, this should remain won't fix.

    ao2’s picture

    @Dave Reid,
    technically we still have one alias per path with the patch from #44, this patch just makes the alias enabled for All Languages, this behaviour is already here when dealing with language neutral content after all.

    Sorry if I might sound harsh, but: have you actually looked at the patch in #44?
    If I am missing anything could you please help me to figure out what?

    Regards,
    Antonio

    MichaelP’s picture

    Subscribing to @ao2's comment at #84.

    The patch at #44, or some alternative, would appear to be necessary for a multilingual site, or else it's no pathauto for us !!

    pfx’s picture

    Subscribe +1

    cainrus’s picture

    patch for last 6.x-2.x-dev-2011-Jan-04 version (see #79 and #44 comment).

    Summit’s picture

    newest .dev pathauto has the possibility to set per nodetype per language the tokens which you want. There is a language token which can be included.
    It is working great with the newest token dev.!

    greetings,
    Martijn

    jessehs’s picture

    On issue that has come up with the patch in #44: Let's say a node type is language neutral, and an alias is created (with no language attribute). The node type is changed to be language specific, and the node is updated to be English. Upon pathauto re-working the alias, it adds a "-0" to the end of the path. If the path_redirect module is enabled, this will also add a redirect from the original alias to the "-0" one.

    When creating an alias, it would be good while creating a language-specific alias, to first see if there is a *language neutral* automatically generated alias.

    huah’s picture

    Open and edit "pathauto.inc" file。
    change pathauto_create_alias() function。
    Add $language = LANGUAGE_NONE ;

    function pathauto_create_alias($module, $op, $source, $data, $type = NULL, $language = LANGUAGE_NONE) {
    // Retrieve and apply the pattern for this content type.
    $language = LANGUAGE_NONE ;
    $pattern = pathauto_pattern_load_by_entity($module, $type, $language);
    if (empty($pattern)) {
    // No pattern? Do nothing (otherwise we may blow away existing aliases...)
    return '';
    }
    ...

    Then ,all new alias will auto set to all laguage .

    Change old alias :UPDATE `url_alias` SET `language` = 'und'

    ----------------------------------------------------------------------
    把现有的所有alias设为不限语言,可直接在数据库中操作:UPDATE `url_alias` SET `language` = 'und'

    把所有新建的节点的自动alias设为不限语言:
    打开pathauto模块下的pathauto.inc,改pathauto_create_alias函数。在函数最上方加一行代码 设定$language = LANGUAGE_NONE ; 这样,新建的所有节点其alias都会设为不限语言。

    Drupa1ish’s picture

    #90 works for D7 version also. Thanks!

    mstrelan’s picture

    Please do not use #90! You can implement hook_pathauto_alias_alter() and simply set $context['language'] = LANGUAGE_NONE;. In fact this is the example given by pathauto itself!

    <?php
    function hook_pathauto_alias_alter(&$alias, array &$context) {
      // Force all aliases to be saved as language neutral.
      $context['language'] = LANGUAGE_NONE;
    }
    ?>
    
    Drupa1ish’s picture

    @mstrelan Thanks for the tip!

    Nux’s picture

    If you want to make a simple netural path module just create neutral_paths.info file:

    name = Language Neutral Paths
    description = Makes all future url aliases language neutral. Note! This is a clone of an actual module. Do not update it. To make previous paths neutral run SQL: UPDATE `url_alias` SET `language` = 'und'
    
    core = 7.x
    dependencies[] = pathauto 

    And neutral_paths.module file:

    
    /**
     * Implements hook_pathauto_alias_alter().
     *
     * Resets the language before saving the alias
     */
    function neutral_paths_pathauto_alias_alter(&$alias, array &$context) {
      // Force all aliases to be saved as language neutral.
      $context['language'] = LANGUAGE_NONE;
    } 
    

    Just copy both files to "neutral_paths" directory in your "modules" directory and enable the module.

    banoodle’s picture

    Issue summary: View changes

    I tried the module approach in #94. It doesn't seem to be doing anything (I definitely cleared cache). It is showing up as a module that I can enable, but if I take a language neutral node and set it to a language, the alias for that node is still being set to that language.

    I really need all aliases to stay language neutral.

    I'm running Pathauto 7.x-1.2

    I haven't tried any of the patches on this discussion yet (they're all failed) - but I guess I'll try that on my dev instance next - they seemed to help some people so maybe that will work.

    If anyone has any advice - I would greatly appreciate it.

    banoodle’s picture

    I applied the patch in #44 and it applied successfully.

    It is only partially working for me.

    From the alias UI, it appears the alias is getting set to all languages as desired.

    However, the newly created/updated alias doesn't actually work (it's still functioning like node/675 for example).

    In the database url_alias table, I can see that the problem is the language is blank rather than set to 'und'

    If I edit the alias through the UI, make no changes and just save it, then the alias does work and the value in the database is set to 'und'

    This sounds like the problem at https://www.drupal.org/node/1254912.

    So I just upgraded pathauto to the latest dev branch (7.x-1.2+22-dev) as it fixes the null language for alias problem. I tested it and it works, but of course without the patch in #44 I'm back to language-specific aliases which is what I don't want.

    So I applied patch #44 to version 7.x-1.2+22-dev of pathauto. Application was successful, and now I'm back to where drupal is almost doing what I want but not quite (it's set to all languages in the ui but blank in the database until the alias is edited and saved).

    Argh!