summaryrefslogtreecommitdiff
path: root/modules/translation
diff options
context:
space:
mode:
authorGábor Hojtsy <gabor@hojtsy.hu>2007-06-30 21:00:51 +0000
committerGábor Hojtsy <gabor@hojtsy.hu>2007-06-30 21:00:51 +0000
commita3d75e547f62174fe9fa2b5c3f9684b620612b00 (patch)
treea66f3f7c89b65ce621521d1bbd3b2e840ce505c2 /modules/translation
parent9e6ef53c2c3f15ad580ebfe71b53899eb4683c11 (diff)
downloadbrdo-a3d75e547f62174fe9fa2b5c3f9684b620612b00.tar.gz
brdo-a3d75e547f62174fe9fa2b5c3f9684b620612b00.tar.bz2
#141996 by Jose A Reyero and myself: translation block to switch interface languages by default, and even content languages, when a translation module provides the alternate links
Diffstat (limited to 'modules/translation')
-rw-r--r--modules/translation/translation.module41
1 files changed, 41 insertions, 0 deletions
diff --git a/modules/translation/translation.module b/modules/translation/translation.module
index 674492d98..c7f464cd2 100644
--- a/modules/translation/translation.module
+++ b/modules/translation/translation.module
@@ -336,3 +336,44 @@ function translation_node_get_translations($tnid) {
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 translations of the node accessible
+ * to the current user 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 ($links as $langcode => $link) {
+ if (isset($paths[$langcode])) {
+ // Translation in a different node.
+ $links[$langcode]['href'] = $paths[$langcode];
+ }
+ else {
+ // No translation in this language, or no permission to view.
+ unset($links[$langcode]);
+ }
+ }
+ }
+}