Index: includes/menu.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/menu.inc,v retrieving revision 1.179 diff -u -p -r1.179 menu.inc --- includes/menu.inc 17 Jun 2007 14:55:39 -0000 1.179 +++ includes/menu.inc 17 Jun 2007 18:58:07 -0000 @@ -849,7 +849,7 @@ function menu_get_active_help() { // Don't return help text for areas the user cannot access. return; } - $path = ($item['type'] == MENU_DEFAULT_LOCAL_TASK) ? $item['tab_parent'] : $item['path']; + $path = ($item['type'] == MENU_DEFAULT_LOCAL_TASK) ? $item['tab_parent'] : $_GET['q']; foreach (module_list() as $name) { if (module_hook($name, 'help')) { Index: modules/locale/locale.module =================================================================== RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v retrieving revision 1.179 diff -u -p -r1.179 locale.module --- modules/locale/locale.module 17 Jun 2007 17:41:40 -0000 1.179 +++ modules/locale/locale.module 17 Jun 2007 18:58:08 -0000 @@ -55,6 +55,9 @@ function locale_help($section) { return '

'. t("This page allows you to export Drupal strings. The first option is to export a translation so it can be shared. The second option generates a translation template, which contains all Drupal strings, but without their translations. You can use this template to start a new translation using various software packages designed for this task.") .'

'; case 'admin/build/translate/search': return '

'. t("It is often convenient to get the strings from your setup on the export page, and use a desktop Gettext translation editor to edit the translations. On this page you can search in the translated and untranslated strings, and the default English texts provided by Drupal.", array("@export" => url("admin/build/translate/export"))) .'

'; + + case 'admin/build/block/configure/locale/0': + return '

'. t("This block is only shown if you have at least two languages enabled and you have a language negotiation setting different from 'none', so you have different web addresses for different language versions.", array('@languages' => 'admin/settings/language', '@configuration' => url('admin/settings/language/configure'))) .'

'; } } @@ -493,3 +496,42 @@ function _locale_batch_import($filepath, $context['results'][] = $filepath; } } + +// --------------------------------------------------------------------------------- +// Language switcher block + +/** + * Implementation of hook_block(). + * Displays a language switcher. Translation links may be provided by other modules. + */ +function locale_block($op = 'list', $delta = 0) { + if ($op == 'list') { + $block[0]['info'] = t('Language switcher'); + 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; + } +} Index: modules/translation/translation.module =================================================================== RCS file: /cvs/drupal/drupal/modules/translation/translation.module,v retrieving revision 1.1 diff -u -p -r1.1 translation.module --- modules/translation/translation.module 15 Jun 2007 18:40:14 -0000 1.1 +++ modules/translation/translation.module 17 Jun 2007 18:58:08 -0000 @@ -336,3 +336,39 @@ function translation_node_get_translatio function translation_supported_type($type) { return variable_get('language_' . $type, 0) == TRANSLATION_ENABLED; } + +/** + * Return paths of all translations of a node, based on + * its Drupal path. + * + * @param $path + * A Drupal path, for example node/432. + * @return + * An array of paths of all translations of the node + * keyed with language codes. + */ +function translation_path_get_translations($path) { + $paths = array(); + // Check for a node related path, and for its translations. + if ((preg_match("!^node/([0-9]+)(/.+|)$!", $path, $matches)) && ($node = node_load((int)$matches[1])) && !empty($node->tnid)) { + foreach (translation_node_get_translations($node->tnid) as $language => $translation_node) { + $paths[$language] = 'node/'. $translation_node->nid . $matches[2]; + } + } + return $paths; +} + +/** + * Implementation of hook_alter_translation_link(). + * + * Replaces links with pointers to translated versions of the content. + */ +function translation_translation_link_alter(&$links, $path) { + if ($paths = translation_path_get_translations($path)) { + foreach ($paths as $langcode => $path) { + if (isset($links[$langcode])) { + $links[$langcode]['href'] = $path; + } + } + } +}