locale_block

Definition

locale_block($op = 'list', $delta = 0)
modules/locale/locale.module, line 564

Description

Implementation of hook_block(). Displays a language switcher. Translation links may be provided by other modules.

Code

<?php
function locale_block($op = 'list', $delta = 0) {
  if ($op == 'list') {
    $block[0]['info'] = t('Language switcher');
    // Not worth caching.
    $block[0]['cache'] = BLOCK_NO_CACHE;
    return $block;
  }

  // Only show if we have at least two languages and language dependent
  // web addresses, so we can actually link to other language versions.
  elseif ($op == 'view' && variable_get('language_count', 1) > 1 && variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE) != LANGUAGE_NEGOTIATION_NONE) {
    $languages = language_list('enabled');
    $links = array();
    foreach ($languages[1] as $language) {
      $links[$language->language] = array(
        'href'       => $_GET['q'],
        'title'      => $language->native,
        'language'   => $language,
        'attributes' => array('class' => 'language-link'),
      );
    }

    // Allow modules to provide translations for specific links.
    // A translation link may need to point to a different path or use
    // a translated link text before going through l(), which will just
    // handle the path aliases.
    drupal_alter('translation_link', $links, $_GET['q']);

    $block['subject'] = t('Languages');
    $block['content'] = theme('links', $links, array());
    return $block;
  }
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.