--- C:/localizer.module	Wed Dec 05 14:14:58 2007
+++ W:/localizer.module	Tue Dec 04 17:55:25 2007
@@ -400 +400,8 @@
-  $output = theme('item_list', localizer_block_switchuilocale_links(variable_get('localizer_switchblock_showflags', TRUE), variable_get('localizer_switchblock_showlangname',TRUE), variable_get('localizer_switchblock_flagseparator', ' ')));
+	
+	//Ensure at least one link is returned to avoid theming with no content
+	$links = localizer_block_switchuilocale_links(variable_get('localizer_switchblock_showflags', TRUE), variable_get('localizer_switchblock_showlangname',TRUE), variable_get('localizer_switchblock_flagseparator', ' '));
+	if ($links != '')
+  	$output = theme('item_list', $links);
+  else
+  	$output = '';
+  
@@ -421,0 +429,6 @@
+			//Check that the node has a translation for this locale
+			//otherwise don't show that link
+			$orig_node = $_GET['q'];		
+			$dest_node = localizernode_get_localizedpath($_GET['q'], $lang);
+			if ($orig_node!='' && $orig_node!='node' && $orig_node == $dest_node) continue;
+
@@ -791,0 +805 @@
+
@@ -792,0 +807 @@
+    $a_locales = array_keys($valid_locales);
@@ -830 +845,3 @@
-      if($localebyhostname != $pathlocale) {
+			
+			//If locales of the host and path don't match, redirect to the right domain
+      if($localebyhostname != $pathlocale && $pathlocale!='') {
@@ -831,0 +849 @@
+        	$origin = $_GET['q'];
@@ -832,0 +851,20 @@
+          //If the node doesn't provide any translation
+          //get the right domain for the page and redirect
+          if ($origin == $destination)
+          {
+						//Check if the locale for the path is right, if not, set it to default
+						if (!localizer_isvaliduilocale($pathlocale)) $pathlocale = localizer_get_defaultuilocale();
+          	
+          	//Get the node with its name instead of its number
+          	global $base_path;
+          	$localized_node = localizer_get_destination($pathlocale);
+          	$localized_host = variable_get('localizer_switch_hostname_'.$pathlocale,$currenthost);
+          	$destination = 'http://'.$localized_host.$base_path.$localized_node;
+          	
+          	//Check that the domain are actually different before redirecting to avoid endless loops
+          	if ($_SERVER['HTTP_HOST'] != $localized_host) $f_redirect = TRUE;
+          }
+          else
+          	$f_redirect = TRUE;
+          
+          if($f_redirect) drupal_goto($destination);
@@ -837,2 +874,0 @@
-        if($destination != $_GET['q']) {
-          drupal_goto($destination);
@@ -839,0 +876,2 @@
+      else {
+        $destination = $_GET['q'];
