Download & Extend

How to have URL paths of all translated nodes be synchronized based on the source node

Project:Pathauto
Version:7.x-1.x-dev
Component:I18n stuff
Category:support request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Note: This might seem similar to #737746: using language English as for all other languages as the url alias and #736178: Add a [node:source] token for source node of a translated node but it is not a duplicate (related yes - not the same though). It is meant to serve as a guide to get as close as possible to the desired goal (that's why I've filed it as a support request). It lists things that could be done in order to make this procedure as easy as possible, so it might include links to other issues, so it doesn't belong to documentation either. It's more like a meta-issue.

This is work in progress, so bare with me as I update this while testing and researching. Once It is over, I'll also make sure it complies to the Issue summary standards.

Problem/Motivation

The goal is simple and seems to be a popular request: have it so that all URLs of the translations of a node have the same path (except of course the language prefix). Like so:

en/page/bike
it/page/bike
el/page/bike

Proposed resolution

Issue #1: You can manually add the path for translated nodes so that it matches the English source node. If translations of nodes are set to be synched though, then once the English node is edited, all translation nodes' URLs get synched/updated too. This resets the translation node's URLs to whatever pattern is defined (usually, the default content/[node:title]).

In order to remedy this and keep the translations synched while not loosing the manually entered path, the Pathauto persistent state module came to life. There is an ongoing effort to get this functionality in pathauto: #936222: Merge in pathauto_persist module functionality to prevent losing manual aliases with node_save() calls

At the time of writing this, this patch for D7 in post #40 works just fine + there is also one for D6.

If you happen to apply this patch in a working site that already has nodes that have translations, you might get this error:

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'my_drupal_db.pathauto' doesn't exist: SELECT 1 AS expression FROM {pathauto} pathauto WHERE ( (entity_type = :db_condition_placeholder_0) AND (entity_id = :db_condition_placeholder_1) ) FOR UPDATE; Array ( [:db_condition_placeholder_0] => node [:db_condition_placeholder_1] => 6 ) in pathauto_entity_state_save() (line 222 of /var/www/sites/all/modules/pathauto/pathauto.module).

Don't worry! Been there and out of it. Read here how you can solve it ;)

Issue #2: Manually editing the URLs of translated nodes + path persistence does the trick, but we need this to be achieved as "transparently" as possible. So far here's what can be done to automate things a bit:

- Set the default pattern to: [node:content-type:machine-name]/[node:source:title]

Issue #3: This gets half of the job done because it does create proper paths for translations of nodes, but only if the source node exists. In other words, it would work fine for translated nodes since a source nodes exists, but when a new node is created, it would end up having a path like:

en/page

This is no good, because the prefix is there of course, so is the [node:content-type:machine-name] part, but there is no title. If we add translations to this node, they wold be:

it/page
el/page

The trick here is to go to the English pattern for each content type and set it to [node:content-type:machine-name]/[node:title]. Now, all you have to do is make sure that each new content added is first created in its English version. What is tedious about this step is that

a) you need to add this pattern to *every single* English content type pattern and it gets worse as the number of content types in your site increase.
b) you also need to remember to add this very same pattern to the English pattern of each new content type you add.

I've filed #1245734: Add generic, per-language patterns.. This would spare us from the above (a & b).

Comments

#1

Title:How to have URL paths of all translated nodes be the same.» How to have URL paths of all translated nodes be synchronized based on the source node

#2

You could write a custom token that is the source title such as what was written here:

http://drupal.org/node/736178#comment-3626692

You just need to make sure that you are using the new title when creating and editing the node.

Kristen