Pathauto and Localizer

Last modified: October 26, 2008 - 22:23

I was looking for a way to include node language into pathauto recognizable variables, this is how I managed to do it, you will be able to use [locale] in your nodes path.

Implementation with a custom Module

First create a new module, with modulename.module and insert this code:

<?php
/**
* adds custom tokens for pathauto
*/
function modulename_tokens_token_values($type, $object = NULL, $options = array()) {

    global
$locale;

    if (
$type == 'node') {

       
$result = db_query("SELECT locale FROM {localizernode} WHERE nid='%d'", $object->nid);
       
$nodelocale = db_fetch_object($result);       
       
       
$values['locale'] = $nodelocale->locale;
       
        return
$values;

    }
 
}

/**
* adds custom tokens to the token listing
*/
function modulename_tokens_token_list($type = 'all') {

    if (
$type == 'node' || $type == 'all') {
       
       
$tokens['node']['locale'] = t('Will write node\'s locale');

        return
$tokens;
       
    }
   
}
?>

Activate in ( administer >> site building >> modules ) your drupal module section and you will see in pathauto the new token will appear !

 
 

Drupal is a registered trademark of Dries Buytaert.