You are here

function globallink_interface_get_translated in GlobalLink Connect for Drupal 7.6

Gets number of translated interfaces.

Parameters

string $pd4: The project director details.

array $globallink_arr: Array of GlobalLink objects.

Return value

int The number of translated interfaces.

2 calls to globallink_interface_get_translated()
globallink_auto_receive in ./globallink.module
Automatically receives translated contents.
globallink_interface_receive_form_submit in globallink_interface/globallink_interface_receive.inc
Handles interface form submission.

File

globallink_interface/globallink_interface.inc, line 340

Code

function globallink_interface_get_translated($pd4, &$globallink_arr) {
  module_load_include('inc', 'globallink', 'globallink');
  $count = 0;
  foreach ($globallink_arr as $globallink) {
    $target_xml = globallink_download_target_resource($pd4, $globallink->targetTicket);
    if ($globallink->sourceDeleted) {
      continue;
    }
    if (!isset($target_xml)) {
      continue;
    }
    $count++;
    $language = globallink_get_drupal_locale_code($globallink->targetLocale);
    $translated_arr = globallink_interface_get_translated_items($target_xml);
    try {
      $lid = $translated_arr['lid'];
      foreach ($translated_arr as $attribute => $translations) {
        if ($attribute == 'lid') {
          continue;
        }
        $interface = '';
        if ($attribute == 'source') {
          $interface = globallink_load_source_data($translations['lid']);
          if ($interface == '') {
            throw new Exception('Source string not found for interface id ' . $lid . ' and field name ' . $attribute);
          }
        }
        $textgroup = 'default';
        $context = '';
        if (!empty($interface[0]->textgroup)) {
          $textgroup = $interface[0]->textgroup;
        }
        if (!empty($interface[0]->context)) {
          $context = $interface[0]->context;
        }
        $report =& drupal_static(__FUNCTION__, array(
          'additions' => 0,
          'updates' => 0,
          'deletes' => 0,
          'skips' => 0,
        ));
        _locale_import_one_string_db($report, $language, $context, $interface[0]->source, $translations['translation'], $textgroup, $translations['location'], LOCALE_IMPORT_OVERWRITE);
      }
      if ($globallink->status != 'Error') {
        if ($globallink->status != 'Node Deleted') {
          globallink_send_download_confirmation($globallink->targetTicket, $pd4);
        }
        globallink_interface_update_status($globallink);
      }
      else {
        $count--;
      }
    } catch (SoapFault $se) {
      $count--;
      globallink_interface_update_status($globallink, 'Error');
      form_set_error('', t('Web Services Error: @faultcode - @faultstring', array(
        '@faultcode' => $se->faultcode,
        '@faultstring' => $se->faultstring,
      )));
    } catch (Exception $ex) {
      $count--;
      globallink_interface_update_status($globallink, 'Error');
      form_set_error('', t('Error: @message', array(
        '@message' => $ex
          ->getMessage(),
      )));
    }
  }
  return $count;
}