--- org_unique_field.module	2008-10-26 02:27:58.000000000 +0200
+++ unique_field.module	2008-11-25 12:05:37.000000000 +0100
@@ -20,6 +20,8 @@ define('UNIQUE_FIELD_SCOPE_ALL', 'all');
 define('UNIQUE_FIELD_COMP_EACH', 'each');
 define('UNIQUE_FIELD_COMP_ALL', 'all');
 define('UNIQUE_FIELD_FIELDS_TITLE', 'title');
+define('UNIQUE_FIELD_LANGUAGE', 0);
+
 
 /**
  * Implementation of hook_perm()
@@ -46,7 +48,7 @@ function unique_field_nodeapi(&$node, $o
     
     // get list of unique fields for node type
     $fields = variable_get('unique_field_fields_'. $node->type, array());
-    
+
     // if there are unique fields for this node type
     if (count($fields)) {
       
@@ -56,7 +58,6 @@ function unique_field_nodeapi(&$node, $o
       $errmsg = NULL;
       $errfld = array();
       $allmatch = NULL;
-      
       // check fields for node scope
       if ($scope==UNIQUE_FIELD_SCOPE_NODE) {
         $values = array();
@@ -91,7 +92,11 @@ function unique_field_nodeapi(&$node, $o
             $f = $node->$field;
             $value = $f[0];
           }
-          $match = unique_field_match_value($field, $value, $scope, $node->type);
+          // language dependant
+          $languagedependant = variable_get('unique_field_language_'. $node->type, UNIQUE_FIELD_LANGUAGE);   
+          $language = ($languagedependant) ? $node->language : NULL; 
+          
+          $match = unique_field_match_value($field, $value, $scope, $node->type,$language);
           // remove matches of this node
           if ($node->nid && is_array($match) && in_array($node->nid, $match)) {
             $key = array_search($node->nid, $match);
@@ -137,7 +142,7 @@ function unique_field_nodeapi(&$node, $o
 /** 
  * Find nodes with a matching field value within a given scope.
  */
-function unique_field_match_value($field, $values, $scope, $ntype = NULL) {
+function unique_field_match_value($field, $values, $scope, $ntype = NULL,$language = NULL) {
   // generate query if field is title
   if ($field===UNIQUE_FIELD_FIELDS_TITLE) {
     $qtbl = 'node';
@@ -194,6 +199,12 @@ function unique_field_match_value($field
       $qjoin = "JOIN {node} AS node ON {$qtbl}.nid = node.nid";
       $qwhere .= "AND node.type = '". db_escape_string($ntype) ."'";
     }
+    
+    // check language
+    if(UNIQUE_FIELD_LANGUAGE_TYPE)
+    if(!empty($language)) {
+      $qwhere .= " AND node.language = '". db_escape_string($language) ."'";
+    }
   }
   
   // do query
@@ -202,6 +213,7 @@ function unique_field_match_value($field
     $q .= $qjoin;
   }
   $q .= " WHERE ". $qwhere;
+  //var_dump($q);
   $res = db_query($q);
   $nids = array();
   while ($obj = db_fetch_object($res)) {
@@ -249,6 +261,19 @@ function unique_field_node_settings_form
     '#default_value' => variable_get('unique_field_scope_'. $ntype, UNIQUE_FIELD_SCOPE_TYPE),
     '#description' => t('Choose whether the values in the specified fields must be unique among nodes of this content type, among all nodes, or only among the fields of the present node.'),
   );
+  // language depandant
+  if (module_exists('locale')) {
+    $form['unique_field']['unique_field_language'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Language dependant'),
+      '#options' => array(
+        0 => t('Off'),
+        1 => t('On'),
+      ),
+      '#default_value' => variable_get('unique_field_language_'. $ntype, UNIQUE_FIELD_LANGUAGE),
+      '#description' => t('Choose if it just should compare nodes of the same language?'),
+    );   
+  }
   $form['unique_field']['unique_field_comp'] = array(
     '#type' => 'radios',
     '#title' => t('Choose whether values must be unique individually or in combination'),
