You are here

function i18ntaxonomy_translation_save in Internationalization 6

Save taxonomy term translations.

Parameters

$terms: Array of terms indexed by language.

$trid: Optional translation set id.

1 call to i18ntaxonomy_translation_save()
i18ntaxonomy_translation_term_form_submit in i18ntaxonomy/i18ntaxonomy.admin.inc
Form callback: Process vocabulary translation form.

File

i18ntaxonomy/i18ntaxonomy.admin.inc, line 106
Helper functions for taxonomy administration.

Code

function i18ntaxonomy_translation_save($terms, $trid = 0) {

  // Delete old translations for this trid.
  if ($trid) {
    db_query("UPDATE {term_data} SET trid = 0 WHERE trid = %d", $trid);
  }

  // Now pick up all the tids in an array.
  $translations = array();
  foreach (i18n_supported_languages() as $lang => $name) {
    if (isset($terms[$lang]) && ($term = (array) $terms[$lang]) && ($tid = $term['tid'])) {
      $translations[$lang] = $tid;
    }
  }

  // Now set a translation set with all these terms. We need some table locking to avoid race conditions.
  // when other translations created simulaneously. @TODO Find a better way.
  if (count($translations)) {
    db_lock_table('term_data');
    $trid = is_numeric($trid) && $trid ? $trid : i18ntaxonomy_next_trid();
    $params = array_merge(array(
      $trid,
    ), $translations);
    db_query('UPDATE {term_data} SET trid = %d WHERE tid IN(' . db_placeholders($translations) . ')', $params);
    db_unlock_tables();
  }
}