You are here

function lingotek_batch_identify_translations in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.5 lingotek.util.inc \lingotek_batch_identify_translations()
  2. 7.6 lingotek.util.inc \lingotek_batch_identify_translations()

Batch Create: Lingotek Identify Content - create informative lingotek_entity_ data (in lingotek table) for pre-existing content

1 string reference to 'lingotek_batch_identify_translations'
lingotek_set_batch_function in ./lingotek.util.inc
Run a function that sets a batch

File

./lingotek.util.inc, line 2332
Utility functions.

Code

function lingotek_batch_identify_translations($process_batch = FALSE) {
  LingotekLog::trace(__METHOD__);
  $operations = array();
  $existing_languages = language_list();
  $entity_types = lingotek_managed_entity_types();

  // I. Identify field-based translations and set statuses
  $fields_to_test_for_translations = array(
    'body',
  );

  // tables to test for pre-existing translations
  if (module_exists('comment') && db_field_exists('comment', 'comment_body')) {
    $fields_to_test_for_translations[] = 'comment_body';
  }

  // if a translation for a specific language exists in this table then add a translation status in the lingotek table
  foreach ($entity_types as $entity_type => $entity_type_details) {
    foreach ($existing_languages as $langcode => $language_details) {
      $lingotek_locale = Lingotek::convertDrupal2Lingotek($langcode);
      foreach ($fields_to_test_for_translations as $field) {

        // exclude when language is the source of the node
        $entity_ids = lingotek_list_entities_with_field_in_language($entity_type, $field, $langcode, TRUE);
        foreach ($entity_ids as $entity_id) {
          $operations[] = array(
            'lingotek_batch_keystore_worker',
            array(
              $entity_type,
              $entity_id,
              'target_sync_status_' . $lingotek_locale,
              LingotekSync::STATUS_UNTRACKED,
              FALSE,
            ),
          );
        }
      }
    }
  }

  // II. Identify node-based translations and set statuses
  $entity_type = 'node';
  foreach ($existing_languages as $langcode => $language_details) {
    $entity_ids = lingotek_list_nodes_translated_in_language($langcode);
    $lingotek_locale = Lingotek::convertDrupal2Lingotek($langcode);
    foreach ($entity_ids as $entity_id) {
      $operations[] = array(
        'lingotek_batch_keystore_worker',
        array(
          $entity_type,
          $entity_id,
          'target_sync_status_' . $lingotek_locale,
          LingotekSync::STATUS_UNTRACKED,
          FALSE,
        ),
      );
    }
  }
  $batch = array(
    'title' => t('Identifying Existing Translations'),
    'operations' => $operations,
    'finished' => 'lingotek_batch_identify_translations_finished',
  );
  batch_set($batch);

  // If this batch was NOT created from a form_submit() handler, do this to initiate the batch.
  if ($process_batch) {
    batch_process('admin/settings/lingotek/settings');
  }
}