function admin_language_block in Administration Language 6
Implementation of hook_block().
File
- ./
admin_language.module, line 265 - Makes sure all admin pages are displayed in the preferred language of the administrator.
Code
function admin_language_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$block[0]['info'] = t('Language switcher (without administration language)');
$block[0]['cache'] = BLOCK_NO_CACHE;
return $block;
}
elseif ($op == 'view' && variable_get('language_count', 1) > 1 && variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE) != LANGUAGE_NEGOTIATION_NONE) {
$path = drupal_is_front_page() ? '<front>' : $_GET['q'];
$languages = language_list('enabled');
$admin_language = variable_get('admin_language_default', 'en');
$links = array();
foreach ($languages[1] as $language) {
if ($language->language != $admin_language) {
$links[$language->language] = array(
'href' => $path,
'title' => $language->native,
'language' => $language,
'attributes' => array(
'class' => 'language-link',
),
);
}
}
// modify links to point at translated versions when available.
// same behavior as translation_translation_link_alter() but we don't
// remove links when a translation is unavailable.
if (module_exists('translation')) {
if ($paths = translation_path_get_translations($path)) {
$node = node_load(arg(1));
$translations = translation_node_get_translations($node->tnid);
foreach ($links as $langcode => $link) {
if (isset($paths[$langcode]) && $translations[$langcode]->status) {
// Translation in a different node.
$links[$langcode]['href'] = $paths[$langcode];
}
}
}
}
$block['subject'] = t('Languages');
$block['content'] = theme('links', $links, array());
return $block;
}
}