Index: phplist.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/phplist/phplist.module,v
retrieving revision 1.12.2.19
diff -u -r1.12.2.19 phplist.module
--- phplist.module	26 Mar 2009 13:59:44 -0000	1.12.2.19
+++ phplist.module	29 Apr 2009 22:00:49 -0000
@@ -231,6 +231,27 @@
       '#default_value' => variable_get('phplist_pllastname', 'Last Name')
     );
   }
+  if (module_exists('locale')) {
+    $languages = locale_language_list();
+	if (count($languages) > 1) {
+	  $count = 1;
+	  $form['mapping']['phplist_lang'] = array(
+	    '#type' => 'textfield',
+		'#title' => t('Language mapping'),
+		'#default_value' => variable_get('phplist_lang', ''),
+		'#description' => t('Language attribute in phplist, leave blank to disable language mapping.'),
+	  );
+	  foreach ($languages as $key => $value) {
+	    $form['mapping']["phplist_lang_$key"] = array(
+		  '#type' => 'textfield',
+		  '#title' => $value,
+		  '#default_value' => variable_get("phplist_lang_$key", (string)$count),
+		  '#description' => t('phplist attribute table value for !lang', array('!lang' => $value)),
+		);
+		$count++;
+	  }
+	}
+  }
   $form['user'] = array(
     '#title' => 'My Account - My Newsletters options',
     '#type' => 'fieldset'
@@ -766,6 +787,18 @@
     $attrmap[] = array($profilelastname, variable_get('phplist_pllastname', ''));
   }
   
+  if ((($langattr = variable_get('phplist_lang', '')) != '') && module_exists('locale')) {
+    // Map languages to array
+	$languages = locale_language_list();
+	$count = 0;
+	$langmap = array();
+	$langmap[$langattr] = array();
+	foreach ($languages as $key => $value) {
+	  $langmap[$langattr][$key] = variable_get("phplist_lang_$key", (string)$count);
+	  $count++;
+	}
+  }
+  
   if ($phplistid != '') {
     db_set_active('phplist');
     $result = db_query("UPDATE {$prefix['user']}user SET email='%s', modified=NOW(), htmlemail=%d, confirmed=1 WHERE id=%d", ($user->mail == '' ? $user->init : $user->mail), ($user->phplist_html == 0 || $user->phplist_html == '' ? 1 : 0), $phplistid);
@@ -808,6 +841,21 @@
     }
   }
   
+  // Synchronise language
+  if (module_exists('locale')) {
+    if (isset($user->language)) {
+	  $lang = $user->language;
+	}
+	else {
+	  global $language;
+	  $lang = $language->language;
+	}
+	foreach ($langmap as $langattr => $langs) {
+      if (PHPLIST_DEBUG) drupal_set_message('Synchronised language '. $lang .' : '. $langs[$lang]);
+      _phplist_update_attribute($langattr, 'radio', $langs[$lang], $phplistid);
+	}
+  }
+  
   db_set_active('default');
 }
 
@@ -1240,6 +1288,19 @@
     'subscribe' => 'Subscribe',
   );
   
+  if (module_exists('locale') && variable_get('phplist_lang', '') != '') {
+    global $language;
+	$lang = $language->language;
+    $attr_name = variable_get('phplist_lang', '');
+	$prefix = _phplist_dbconn();
+	db_set_active('phplist');
+    $attrid = db_result(db_query("SELECT id FROM {$prefix['user']}attribute WHERE name='$attr_name'"));
+	if ($attrid) {
+	  $data["attribute$attrid"] = variable_get("phplist_lang_$lang", '1');
+	  drupal_set_message($lang);
+	}
+  }
+  
   $lists = _phplist_get_public_lists($user);
 
   foreach ($lists as $l) {

