diff options
Diffstat (limited to 'modules/translation/translation.module')
-rw-r--r-- | modules/translation/translation.module | 59 |
1 files changed, 49 insertions, 10 deletions
diff --git a/modules/translation/translation.module b/modules/translation/translation.module index 9a6a54924..837e1abde 100644 --- a/modules/translation/translation.module +++ b/modules/translation/translation.module @@ -201,19 +201,57 @@ function translation_form_node_form_alter(&$form, &$form_state) { /** * Implements hook_node_view(). * - * Display translation links with native language names, if this node - * is part of a translation set. + * Display translation links with native language names, if this node is part of + * a translation set. If no language provider is enabled "fall back" to the + * simple links built through the result of translation_node_get_translations(). */ function translation_node_view($node, $view_mode) { + // If the site has no translations or is not multilingual we have no content + // translation links to display. if (isset($node->tnid) && drupal_multilingual() && $translations = translation_node_get_translations($node->tnid)) { - $path = 'node/' . $node->nid; - $links = language_negotiation_get_switch_links(LANGUAGE_TYPE_INTERFACE, $path); - if (is_object($links)) { - $links = $links->links; - // Do not show link to the same node. - unset($links[$node->language]); - $node->content['links']['#links'] = array_merge($node->content['links']['#links'], $links); + $languages = language_list('enabled'); + $languages = $languages[1]; + + // There might be a language provider enabled defining custom language + // switch links which need to be taken into account while generating the + // content translation links. As custom language switch links are available + // only for configurable language types and interface language is the only + // configurable language type in core, we use it as default. Contributed + // modules can change this behavior by setting the system variable below. + $type = variable_get('translation_language_type', LANGUAGE_TYPE_INTERFACE); + $custom_links = language_negotiation_get_switch_links($type, "node/$node->nid"); + $links = array(); + + foreach ($translations as $langcode => $translation) { + // Do not show links to the same node, to unpublished translations or to + // translations in disabled languages. + if ($translation->status && isset($languages[$langcode]) && $langcode != $node->language) { + $language = $languages[$langcode]; + $key = "translation_$langcode"; + + if (isset($custom_links->links[$langcode])) { + $links[$key] = $custom_links->links[$langcode]; + } + else { + $links[$key] = array( + 'href' => "node/{$translation->nid}", + 'title' => $language->native, + 'language' => $language, + ); + } + + // Custom switch links are more generic than content translation links, + // hence we override existing attributes with the ones below. + $links[$key] += array('attributes' => array()); + $attributes = array( + 'title' => $translation->title, + 'class' => array('translation-link'), + ); + $links[$key]['attributes'] = $attributes + $links[$key]['attributes']; + } } + + $node->content['links']['#links'] += $links; } } @@ -460,7 +498,8 @@ function translation_path_get_translations($path) { * Replaces links with pointers to translated versions of the content. */ function translation_language_switch_links_alter(array &$links, $type, $path) { - if ($type == LANGUAGE_TYPE_INTERFACE && $paths = translation_path_get_translations($path)) { + $language_type = variable_get('translation_language_type', LANGUAGE_TYPE_INTERFACE); + if ($type == $language_type && $paths = translation_path_get_translations($path)) { $path = explode('/', $path); $node = node_load($path[1]); $translations = translation_node_get_translations($node->tnid); |