Community Documentation

Localizer module (to use with Pathauto)

Last updated March 25, 2010. Created by Wolfflow on June 12, 2007.
Edited by Dave Reid, greggles, weedoo. Log in to edit this page.

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 !

About this page

Drupal version
Drupal 5.x

Site Building Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.