Pathauto and Localizer

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.

In your pathauto_node.inc you need to add these lines:

This one is shown in the pathauto config

<?php
function node_pathauto($op) {
  switch (
$op) {
    case
'settings':
     
$settings['bulkdescr'] =
?>

...
<?php
       
// LOCAL ADDON
       
t('[locale]') => t('The locale used for this node.'),
?>

These will be loading the data

<?php
function node_get_placeholders($node) {
?>

...
<?php
 
// LOCAL ADDON
 
$result = db_query("SELECT locale FROM {localizernode} WHERE nid='%d'", $node->nid);
 
$nodelocale = db_fetch_object($result);
 
$placeholders[t('[locale]')] = pathauto_cleanstring($nodelocale->locale);
?>

Hope this helps someone !

this is ultimately useful!

mohamed_am83 - April 23, 2008 - 09:12

this is ultimately useful! many thanks for sharing!

The right way to do it

weedoo - June 5, 2008 - 20:46

I found the right way to do this, create a new module, in the modulename.module file 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 your drupal module section and you will see in pathauto the new token will appear !

 
 

Drupal is a registered trademark of Dries Buytaert.