Index: country_code.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/country_code/country_code.module,v
retrieving revision 1.63
diff -u -p -r1.63 country_code.module
--- country_code.module	23 Oct 2008 13:31:48 -0000	1.63
+++ country_code.module	23 Oct 2008 19:55:25 -0000
@@ -454,6 +454,52 @@ function country_code_block($op = 'list'
 }
 
 /**
+ * Implementation of hook_country_code_link_alter().
+ *
+ * Alter country switcher links to point to nodes.
+ *
+ */
+function country_code_country_code_link_alter(&$links, $path) {
+  if (module_exists('translation') && $nodes = country_code_path_get_nodes($path)) {
+    $countries = country_code_countries(TRUE);
+    foreach ($nodes as $node) {
+      $node_country = strtolower((substr($node->language, -2, 2)));
+      if (isset($countries[$node_country])) {
+        $links[$node_country] = array(
+          'href' => 'node/' . $node->nid,
+          'title' => $countries[$node_country]->name,
+          'attributes' => array('class' => 'country_code_link'),
+        );
+      }
+    }
+  }
+}
+
+/**
+ * Get an array of nodes in a translation set from a node path.
+ *
+ * @param $path
+ *  A Drupal path.
+ *
+ * @return
+ *  An array of partial node objects.
+ *
+ */
+function country_code_path_get_nodes($path) {
+  $nodes = 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 $node) {
+      $nodes[] = $node;
+    }
+  }
+  return $nodes;
+}
+
+
+
+
+/**
  * Return an object representing the global version of a site.
  */
 function country_code_global() {
