Skip to content

Instantly share code, notes, and snippets.

@iryston
Forked from opi/gist:5144388
Created February 24, 2017 18:26
Show Gist options
  • Save iryston/16d93bc9115ad23a719bcd06f9c6af93 to your computer and use it in GitHub Desktop.
Save iryston/16d93bc9115ad23a719bcd06f9c6af93 to your computer and use it in GitHub Desktop.
Implements hook_language_switch_links_alter() - Alter language switch links.
<?php
/**
* Implements hook_language_switch_links_alter().
*/
function mymodule_language_switch_links_alter(array &$links, $type, $path) {
global $language;
if ($type == LANGUAGE_TYPE_INTERFACE && isset($links[$language->language])) {
foreach ($links as $langcode => &$link) {
// If no translation exists, redirect to frontpage
if (empty($link['href'])) {
$link['href'] = '<front>';
}
// Change default link title
$link['attributes']['title'] = t(
"View this page in !language",
array('!language' => $link['language']->name),
array('langcode' => $link['language']->language)
);
$link['title'] = substr($link['language']->native, 0, 2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment