On this page
Localizer module (to use with Pathauto)
Last updated on
30 April 2025
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:
/**
* 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 !
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion