I'm still pretty new to all this so I might have overlooked something, but I can't seem to get the following to work:

1. Create a node in the default language (English), pathauto creates a user-friendly url path (/something/page-name/).

2. Add a translation (Swedish, Chinese, whatever) and keep the path generated for the default language (/se/something/page-name/ or /cn/something/page-name/). Instead I get a looooong url of url-encoded gibberish.

Right now I have to edit the translated node path manually every time, which wouldn't work in a situation where the site is handed off to a client.

site.com/something/page-name/
site.com/se/something/page-name/
is the pattern most large multilingual sites use (see apple.com for example).

Or am I missing something? Is there an easy solution?

cheers,
Erik

Comments

erikjohansson’s picture

Category: support » feature

I would love to have a [default-language-title-raw] or [se-title-raw] or [fr-title-raw] etc. token.

greggles’s picture

That won't happen in pathauto.

That probably belongs on token module itself or in localization module.

If you are getting a lot of "weird" characters in the URL, I suggest trying the transliteration module. I imagine those are just non ASCII128 characters.

blueblade’s picture

Hi erikjohansson,

Have you get pathauto to generate URLs like those you wrote here:

site.com/something/page-name/
site.com/se/something/page-name/

When I set a node language to the default language, I do get URLs like

site.com/something/page-name/

but when I am looking at the same page but in a different language, instead of getting

site.com/se/something/page-name/

I get

site.com/se/node/page-name/

Would you mind sharing with me how you get yours to work?

Many thanks!!

BB

mdorrell’s picture

I had to do this as well. I wrote a new token for the url_alias to use. I should note this was for Drupal 6. Here is my code for that:

/**
 * Implementation of hook_token_list
 */
function MODULENAME_token_list($type){
  if ($type == 'node' || $type == 'all') {
    $tokens['user']['default-language-path'] = 'The url path of the node this node was translated from.';
  }
  return $tokens;
}

/**
 * Implementation of hook_token_values
 */
function MODULENAME_token_values($type, $object = NULL, $options = array()) {
  $tokens = array();
  if ($type == 'node' || $type == 'all') {
    $node = $object;
    $tokens['default-language-path'] = MODULENAME_get_default_language_path($node->nid);
  }
  return $tokens;

}

/**
 * gets path of node this node was translated from
 * if this is the source node, it just returns the path alias
 */
function MODULENAME_get_default_language_path($nid){
  $node = node_load($nid);
  $tnid = $node->tnid;
  if(!empty($tnid) && $tnid != $node->nid){
    $source_node = node_load($tnid);
    $path = $source_node->path;
  }else{
    $path = drupal_get_path_alias('node/' . $nid);
  }
  return $path;
}
Anonymous’s picture

mdorrell

How do you use your code please?

[I think what I am experiencing is similar. If a node is created in one language and aliased, this alias is broken in another language.]

risca’s picture

I don't know if it could help some how, but with DRUPAL 6.1 this works. Maybe could help for inspiration.

Dave Reid’s picture

Status: Active » Fixed

This token should be available in Drupal 7 with [node:source:url:alias].

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

clashar’s picture

Status: Closed (fixed) » Active

Please explain how to use this [node:source:url:alias].

I have "Pattern for all CV paths" (CV - is content type) as:
job/[current-user:profile-jobseeker:user:uid]/cv/[node:source:url:alias]

so when viewing the node in English I get this URL:
http://www.paris9.kz/emploi/job/1/cv

I want to have URL with "fr/" prefix for French smth like:
http://www.paris9.kz/emploi/fr/job/1/cv

but I get simply:
http://www.paris9.kz/emploi/fr/node/293/

if I tap URL manually "http://www.paris9.kz/emploi/fr/job/1/cv" then it's "Page not found".

I tried to run "update URL aliases", "update automatic nodetitles", but it didn't help.

what is the problem? should I change "Pattern for all CV paths" otherwise?

clashar’s picture

Category: feature » support
Dave Reid’s picture

Category: support » feature
Status: Active » Closed (fixed)

The token will only work if you are using the core Locale and Content Translation modules. When you translate a node from one language (let's say English) to French using the built-in translation UI, the token [node:source:url:alias] of the French node will return 'the-alias/of-my-english-node'.

Please do not continue to re-open long-fixed issues. Please file new support requests for any issues you have.

kwongkkt’s picture

Category: feature » support
Status: Closed (fixed) » Active

The [node:source:url:alias] does not work. Here are the steps to reproduce the problem.

1. brand new drupal site, with Locale and Content Translation enabled.
2. edit "Url alias" in admin/config/search/path/patterns
3. set "Default path pattern for Article (applies to all Article content types with blank patterns below)"
[node:title]
4. Fill in "article" paths and leave blank for "English Article" (which is the source of everything)
[node:source:url:alias]
5. go to create new article in "English" with title
New Article in english
6. save and edit again, the automatic url now is
new-article-english
7. now click on "translate" tab, it says
English (source) New Article in english
8. click "add translation" for one other language, say "Chinese Traditional", using title
New Article in chinese traditional
9. save it and now I expect the automatic alias filled in with
new-article-english
10. but it actually is
node/12

would anyone please suggest anything I missed?

P2Lnl’s picture

Version: 7.x-1.x-dev » 7.x-1.0-rc2
Priority: Normal » Major

I seem to be having the exact same problem. The aliases only work for the default language, even though I have configured the language specific pattern. When manually typed it says the page cannot be found, meaning that this alias is broken or nonexistent. I assume many drupal 7 pathauto+internationalization users have this problem. Does anyone know where it comes from and how it can be fixed?

Cito’s picture

Replying to #7: [node:source:url:alias] does not exist (any more?) in D7, only [node:source:url] and [node:source:url:unaliased]. Both don't work for me, but [node:source:title] is useful.

Dave Reid’s picture

[node:source:url:path] should work for you.

Dave Reid’s picture

Priority: Major » Normal
Dave Reid’s picture

Status: Active » Closed (fixed)

Re-closing.

jreashor’s picture

In case someone needs to do this in Drupal 7 (and since it lacks [node:source:url:alias]), I used the Custom Tokens module with the following PHP.

$path = '';
$tnid = $data['node']->tnid;
if (!empty($tnid) && $tnid != $data['node']->nid) {
  $source_node = node_load($tnid);
  $path = drupal_get_path_alias('node/' . $source_node->nid, $source_node->language);
}
return $path;
melissa.mcw’s picture

Issue summary: View changes

Not sure if people are still having this issue. I found that [node:source:url:path] does not, in fact, work. Instead I built a custom module, given that #18 was contingent on the Custom Tokens module being installed -- I did not want to go this route bc it was too impactful on the database.

The module code is :

<?php
/**
* @file
*custom_token module
*
* Provides a token to reference the url in the English language
*/
/**
* Implementation of hook_help()
*/
function MODULE_NAME_token_help($path, $arg) {
if ($path == 'admin/help#hid_custom_token') {
$txt = 'Provides a token to reference the url in the English language.';
return '

'. t($txt) .'

';
} // if help
} // function hid_custom_token_help
/**
* Implementation of hook_token_info
*/
function MODULE_NAME_token_token_info(){
$info['tokens']['node']['english-language-path'] = array(
'name' => t('HID Custom URL path alias'),
'description' => t('Token used to set URL path alias in English for regional languages.'),
);
return $info;
} // function hid_custom_token_token_info
/**
* Implementation of hook_tokens
*/
function MODULE_NAME_tokens($type, $tokens, array $data = array(), array $options = array()) {
if (isset($tokens['english-language-path'])) {
$tnid = $data['node']->tnid;
if (!empty($tnid)) {
$translations = translation_node_get_translations($tnid);
if (!empty($translations['en'])) {
$path = drupal_get_path_alias('node/' . $translations['en']->nid, 'en');
return array('[node:english-language-path]' => $path);
} // if has english translation
} // if has source node info
} // if right token is set
} // function hid_custom_token_tokens

It should also be said that once this token is implemented it will take the ENGLISH URL path.
Hope this helps someone, this is the only thing that seemed to work for my particular site.

Jinghan Wang’s picture

Thanks for melissa.mcw's solution. It works on my site.

However, there is a small error said "Undefined index: node" and "Trying to get property of non-object". The module seems call the data variable twice, and the variable is different in each time. Not sure if it is the problem of my own. Hope some one can give an idea.

Thanks!

japerry’s picture

Version: 7.x-1.0-rc2 » 7.x-1.x-dev
Category: Support request » Bug report
Priority: Normal » Major
Status: Closed (fixed) » Active
Issue tags: +affects Drupal.org

This appears still broken. #12 is exactly how you can reproduce this bug.

Will dive deeper through the debugger, but this is our steps:

First, configure the url aliases:
Default path pattern for Page (applies to all Page content types with blank patterns below) : "" (none, we customize each one)
"Pattern for all Catalan Page paths" : [node:source:url:path]

Next add content:
node/add/page, creating the source node.
add 'drupal-8.0' as the url alias for the source node (english)
save page. (Node id: 1234569)
Alias is: http://drupal.org/drupal-8.0

Next add translation
from the source node page just created:
-> add translation -> catalan
-> make sure automatic alias is checked (default)
-> Save page. The catalan page as Node id: 1234571
But the alias is: http://drupal.org/ca/node/1234569
=> It should be http://drupal.org/ca/drupal-8.0

jadhavdevendra’s picture

This is still broken..!! :(

Jorge Navarro’s picture

This works -> [node:source:title]