Index: country_code.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/country_code/country_code.module,v
retrieving revision 1.68
diff -u -p -r1.68 country_code.module
--- country_code.module	25 Oct 2008 01:18:12 -0000	1.68
+++ country_code.module	27 Oct 2008 17:52:43 -0000
@@ -104,28 +104,45 @@ function _country_code_init_language() {
 
   $languages = language_list('enabled');
   $languages = $languages[1];
-  $languages = array_intersect_key($languages, country_code_languages());
+  $country_languages = array_intersect_key($languages, country_code_languages());
 
   // Recognize a language passed through GET or a language set in the session.
   // Only accept an incoming language if it's one of the current country's languages.
-  if (isset($_GET['language']) && isset($languages[$_GET['language']])) {
+  if (isset($_GET['language']) && isset($country_languages[$_GET['language']])) {
     $_SESSION['country_code_language'] = $_GET['language'];
   }
   // Only accept a session language if it's one of the current country's languages.
-  if (isset($_SESSION['country_code_language']) && isset($languages[$_SESSION['country_code_language']])) {
-    $language = $languages[$_SESSION['country_code_language']];
-    return;
-  }
-  // If a language is in the session but it's invalid for the current country, drop it
-  // from the session.
-  else {
-    unset($_SESSION['country_code_language']);
+  if (isset($_SESSION['country_code_language'])) {
+    $country_language_long = country_code_get_country_language($_SESSION['country_code_language']);
+    // The long form is not associated directly with the country, so we look for it
+    // in the full set of enabled languages.
+    if (isset($languages[$country_language_long])) {
+      $language = $languages[$country_language_long];
+      return;
+    }
+    // We accept the short form only if it's directly associated with the country.
+    elseif (isset($country_languages[$_SESSION['country_code_language']])) {
+      $language = $country_languages[$_SESSION['country_code_language']];
+      return;
+    }
+    // If a language is in the session but it's invalid for the current country, drop it
+    // from the session.
+    else {
+      unset($_SESSION['country_code_language']);
+    }
   }
 
   if ($country_language = country_code_language()) {
-    if (isset($languages[$country_language])) {
+    $country_language_long = country_code_get_country_language($country_language);
+    // The long form is not associated directly with the country, so we look for it
+    // in the full set of enabled languages.
+    if (isset($languages[$country_language_long])) {
       $language = $languages[$country_language];
     }
+    // We accept the short form only if it's directly associated with the country.
+    elseif (isset($country_languages[$country_language])) {
+      $language = $country_languages[$country_language];
+    }
   }
 }
 
