Index: country_code.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/country_code/country_code.admin.inc,v
retrieving revision 1.33
diff -u -p -r1.33 country_code.admin.inc
--- country_code.admin.inc	24 Oct 2008 11:45:49 -0000	1.33
+++ country_code.admin.inc	27 Oct 2008 20:23:38 -0000
@@ -216,12 +216,6 @@ function country_code_admin_country_lang
     $form['languages'][$lang_code] = _country_code_country_languages_language($country, $language);
   }
 
-  $form['buttons']['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Save changes'),
-    '#disabled' => empty($languages),
-  );
-
   return $form;
 }
 
@@ -242,7 +236,7 @@ function _country_code_country_languages
   );
   $form['operations'] = array(
     '#type' => 'markup',
-    '#value' => l(t('delete'), 'admin/settings/country-code-country/' . $country['country'] . '/languages/delete/' . $language->language),
+    '#value' => l(t('delete'), 'admin/settings/language/delete/' . $language->language),
   );
 
   return $form;
Index: country_code.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/country_code/country_code.install,v
retrieving revision 1.14
diff -u -p -r1.14 country_code.install
--- country_code.install	23 Oct 2008 09:14:40 -0000	1.14
+++ country_code.install	27 Oct 2008 20:23:38 -0000
@@ -45,34 +45,6 @@ function country_code_schema() {
     'primary key' => array('country'),
   );
 
-  $schema['country_code_country_language'] = array(
-    'description' => t('List of all available languages indexed by country.'),
-    'fields' => array(
-      'country' => array(
-        'type' => 'varchar',
-        'length' => 12,
-        'not null' => TRUE,
-        'default' => '',
-        'description' => t("Country code, e.g. 'us' or 'br'."),
-      ),
-      'language' => array(
-        'type' => 'varchar',
-        'length' => 12,
-        'not null' => TRUE,
-        'default' => '',
-        'description' => t("Language code, e.g. 'de' or 'en-US'."),
-      ),
-      'weight' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => 0,
-        'size' => 'tiny',
-        'description' => t('The weight of this record.'),
-      ),
-    ),
-    'primary key' => array('country', 'language'),
-  );
-
   return $schema;
 }
 
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 20:23:40 -0000
@@ -104,16 +104,16 @@ function _country_code_init_language() {
 
   $languages = language_list('enabled');
   $languages = $languages[1];
-  $languages = array_intersect_key($languages, country_code_languages());
+  $country_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']];
+  if (isset($_SESSION['country_code_language']) && $country_language_long = country_code_get_country_language($_SESSION['country_code_language'])) {
+    $language = $languages[$country_language_long];
     return;
   }
   // If a language is in the session but it's invalid for the current country, drop it
@@ -123,8 +123,11 @@ function _country_code_init_language() {
   }
 
   if ($country_language = country_code_language()) {
-    if (isset($languages[$country_language])) {
-      $language = $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_long];
     }
   }
 }
@@ -718,62 +721,6 @@ function country_code_country_delete($co
 }
 
 /**
- * Fetch and individual language -> country.
- *
- * @param $language
- *   An language code.
- * @param $country
- *   An country code.
- *
- * @return
- *   A single record in array format, or FALSE if none matched the incoming
- *   country code/language.
- */
-function country_code_language_load($language, $country) {
-  $sql = "SELECT * FROM {country_code_country_language} WHERE country = '%s' AND language = '%s'";
-  $result = db_query($sql, $country, $language);
-  if ($record = db_fetch_array($result)) {
-    return $record;
-  }
-  else {
-    return FALSE;
-  }
-}
-
-/**
- * Inserts a new language for a country, or updates an existing one.
- *
- * @param $record
- *   A language record to be saved. If language already exists for the given
- *   country in database, the record will be updated. Otherwise, a new record
- *   will be inserted into the database.
- * @return
- *   The flag SAVED_NEW or SAVED_UPDATE based on the operation performed.
- */
-function country_code_language_save($record) {
-  return country_code_language_load($record['language'], $record['country']) ? drupal_write_record('country_code_country_language', $record, array('country', 'language')) : drupal_write_record('country_code_country_language', $record);
-}
-
-/**
- * Deletes a language for a given country, or all languages for that country.
- *
- * @param $country
- *   The country code of the country to be referenced.
- * @param $language
- *   The language code of the language to be deleted. If none is given, all languages
- *   for the given country are deleted.
- */
-function country_code_language_delete($country, $language = NULL) {
-  if ($language) {
-    db_query("DELETE FROM {country_code_country_language} WHERE country = '%s' AND language = '%s'", $country, $language);
-  }
-  else {
-    db_query("DELETE FROM {country_code_country_language} WHERE country = '%s'", $country);
-  }
-}
-
-
-/**
  * Given a country code, return the country name.
  *
  * @return
@@ -785,7 +732,7 @@ function country_code_country_name($code
 }
 
 /**
- * Given a country code, return all languages.
+ * Given a country code, return all languages for that country.
  *
  * @return
  *   Array of language objects.
@@ -803,23 +750,24 @@ function country_code_languages($country
     // @TODO: use the MIN weight?
     if ($country == COUNTRY_CODE_GLOBAL) {
       if ($enabled) {
-        $result = db_query("SELECT DISTINCT(l.language), l.weight FROM {country_code_country_language} l INNER JOIN {country_code_country} c ON l.country = c.country AND c.enabled = 1 ORDER BY l.weight");
+        $result = db_query("SELECT DISTINCT(SUBSTRING(c.language, 1, 2)) AS language, g.name, g.native FROM {languages} c INNER JOIN {languages} g ON SUBSTRING(c.language, 1, 2) = g.language WHERE c.enabled = 1 ORDER BY c.weight, c.name");
       }
       else {
-        $result = db_query("SELECT DISTINCT(language), weight FROM {country_code_country_language} ORDER BY weight");
+        $result = db_query("SELECT DISTINCT(SUBSTRING(c.language, 1, 2)) AS language, g.name, g.native FROM {languages} c INNER JOIN {languages} g ON SUBSTRING(c.language, 1, 2) = g.language ORDER BY c.weight, c.name");
       }
     }
     // Otherwise, return a country's languages.
     else {
+      // Upper case is  used for countries in the language codes.
+      $country_upper = strtoupper($country);
       if ($enabled) {
-        $result = db_query("SELECT DISTINCT(l.language), l.weight FROM {country_code_country_language} l INNER JOIN {country_code_country} c ON l.country = c.country AND c.enabled = 1 WHERE l.country = '%s' ORDER BY l.weight", $country);
+        $result = db_query("SELECT c.language AS country_language, SUBSTRING(c.language, 1, 2) AS language, g.name, g.native FROM {languages} c INNER JOIN {languages} g ON SUBSTRING(c.language, 1, 2) = g.language WHERE SUBSTRING(c.language, 4) = '%s' AND c.enabled = 1 ORDER BY c.weight, c.name", $country_upper);
       }
       else {
-        $result = db_query("SELECT language, weight FROM {country_code_country_language} WHERE country = '%s' ORDER BY weight", $country);
+        $result = db_query("SELECT c.language AS country_language, SUBSTRING(c.language, 1, 2) AS language, g.name, g.native FROM {languages} c INNER JOIN {languages} g ON SUBSTRING(c.language, 1, 2) = g.language WHERE SUBSTRING(c.language, 4) = '%s' ORDER BY c.weight, c.name", $country_upper);
       }
     }
     while ($language = db_fetch_object($result)) {
-      $language->name = locale_language_name($language->language);
       $languages[$country][$language->language] = $language;
     }
   }
