f6c03b3216d9badc94da9a49675d64beaf3b4175
 i18n_taxonomy/i18n_taxonomy.module |   52 ++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/i18n_taxonomy/i18n_taxonomy.module b/i18n_taxonomy/i18n_taxonomy.module
index e48db5c..a49b25c 100644
--- a/i18n_taxonomy/i18n_taxonomy.module
+++ b/i18n_taxonomy/i18n_taxonomy.module
@@ -1252,3 +1252,55 @@ function i18n_taxonomy_modules_enabled($modules) {
       }
   }
 }
+
+/**
+ * Implements hook_field_widget_form_alter().
+ */
+function i18n_taxonomy_field_widget_form_alter(&$element, &$form_state, $context) {
+  if (isset($context['instance']['widget']['type']) && $context['instance']['widget']['type'] === 'taxonomy_autocomplete') {
+    $element['#element_validate'] = array('i18n_taxonomy_autocomplete_widget_validate');
+  }
+}
+
+/**
+ * Form element validate handler for taxonomy term autocomplete widget element.
+ */
+function i18n_taxonomy_autocomplete_widget_validate($element, &$form_state) {
+  // Autocomplete widgets do not send their tids in the form, so we must detect
+  // them here and process them independently.
+  $value = array();
+  if ($tags = $element['#value']) {
+    // Collect candidate vocabularies.
+    $field = field_widget_field($element, $form_state);
+    $vocabularies = array();
+    foreach ($field['settings']['allowed_values'] as $tree) {
+      if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) {
+        $vocabularies[$vocabulary->vid] = $vocabulary;
+      }
+    }
+
+    // Translate term names into actual terms.
+    $typed_terms = drupal_explode_tags($tags);
+    foreach ($typed_terms as $typed_term) {
+      // See if the term exists in the chosen vocabulary and return the tid;
+      // otherwise, create a new 'autocreate' term for insert/update.
+      if ($possibilities = taxonomy_term_load_multiple(array(), array('name' => trim($typed_term), 'vid' => array_keys($vocabularies)))) {
+        $term = array_pop($possibilities);
+      }
+      else {
+        $language_interface = i18n_language_interface();
+        $vocabulary = reset($vocabularies);
+        $term = array(
+          'tid' => 'autocreate',
+          'vid' => $vocabulary->vid,
+          'name' => $typed_term,
+          'vocabulary_machine_name' => $vocabulary->machine_name,
+          'language' => (isset($form_state['values']['language'])) ? $form_state['values']['language'] : $language_interface->language, 
+        );
+      }
+      $value[] = (array)$term;
+    }
+  }
+
+  form_set_value($element, $value, $form_state);
+}
\ No newline at end of file
