Index: locale.module =================================================================== RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v retrieving revision 1.171 diff -u -r1.171 locale.module --- locale.module 3 May 2007 09:51:08 -0000 1.171 +++ locale.module 11 May 2007 16:09:00 -0000 @@ -273,6 +273,12 @@ 'locale_languages_overview_form' => array( 'arguments' => array('form' => array()), ), + 'language_link' => array( + 'arguments' => array('link' => NULL), + ), + 'language_item_list' => array( + 'arguments' => array('links' => NULL), + ), ); } @@ -422,3 +428,58 @@ } return $list; } + +// --------------------------------------------------------------------------------- +// Language selection block + +/** + * Implementation of hook_block(). + * + * Displays a language switcher. Translation links may be provided by other modules. + */ +function locale_block($op = 'list', $delta = 0) { + global $user; + if ($op == 'list') { + $block[0]['info'] = t('Language switcher'); + return $block; + } + else if ($op == 'view') { + $links = array(); + foreach (language_list() as $language) { + $links[$language->language] = array('href' => $_GET['q'], 'title' => $language->native, 'options' => array('language' => $language, 'attributes' => array('class' => 'language-link'))); + } + // Allow modules to provide translations for specific links. + // A translation link besides switching the page language may + // need to point to a different path or a translated text before + // going through l() function which will just handle the path aliases + drupal_alter('translation', $links, $_GET['q']); + + $block['subject'] = t('Languages'); + $block['content'] = theme('language_item_list', $links); + return $block; + } +} + +/** + * Themed language links. + * + * @param $links + * Array of links. Each link is an array with 'title', 'href' and 'options' elements. + */ +function theme_language_item_list($links) { + $output = array(); + foreach ($links as $link) { + $output[] = theme('language_link', $link); + } + return theme('item_list', $output); +} + +/** + * Return a themed language link. + * + * @param $link + * Array with 'title', 'href' and 'options' elements + */ +function theme_language_link($link) { + return l($link['title'], $link['href'], $link['options']); +}