/** * Add a document to the Lingotek platform. * * Uploads the translatable object's content in the selected language. * * @param object $translatable_object * A Drupal node object or lingotek ConfigChunk object */ public function addContentDocument(LingotekTranslatableEntity $translatable_object, $with_targets = FALSE) { $success = FALSE; $project_id = $translatable_object->getProjectId(); $source_language = $translatable_object->getSourceLocale(); if (empty($source_language)) { drupal_set_message('Some entities not uploaded because the source language was language neutral.', 'warning', FALSE); LingotekLog::warning('Document @docname not uploaded. Language was language neutral.', array('@docname' => $translatable_object->getDocumentName())); return FALSE; } if ($project_id) { $parameters = array('projectId' => $project_id, 'format' => $this->xmlFormat(), 'sourceLanguage' => $source_language, 'tmVaultId' => $translatable_object->getVaultId()); $parameters['documentName'] = $translatable_object->getDocumentName(); $parameters['documentDesc'] = $translatable_object->getDescription(); $parameters['content'] = $translatable_object->documentLingotekXML(); $parameters['url'] = $translatable_object->getUrl(); $parameters['workflowId'] = $translatable_object->getWorkflowId(); $this->addAdvancedParameters($parameters, $translatable_object); if ($with_targets) { $parameters['targetAsJSON'] = Lingotek::getLanguagesWithoutSourceAsJSON($source_language); $parameters['applyWorkflow'] = 'true'; // API expects a 'true' string $result = $this->request('addContentDocumentWithTargetsAsync', $parameters); } else { $result = $this->request('addContentDocumentAsync', $parameters); } if ($result) { if (isset($result->errors) && $result->errors) { LingotekLog::error(t('Request to send document to Lingotek failed: ') . print_r($result->errors, TRUE), array()); $translatable_object->setStatus(LingotekSync::STATUS_FAILED); $translatable_object->setLastError(is_array($result->errors) ? array_shift($result->errors) : $result->errors); return FALSE; } if (get_class($translatable_object) == 'LingotekConfigSet') { $translatable_object->setDocumentId($result->id); $translatable_object->setProjectId($project_id); $translatable_object->setStatus(LingotekSync::STATUS_CURRENT); $translatable_object->setTargetsStatus(LingotekSync::STATUS_PENDING); // WTD: there is a race condition here where a user could modify a locales- // source entry between the time the dirty segments are pulled and the time // they are set to current at this point. This same race condition exists // for nodes as well; however, the odds may be lower due to number of entries. LingotekConfigSet::setSegmentStatusToCurrentById($translatable_object->getId()); } else { // node assumed (based on two functions below... $entity_type = $translatable_object->getEntityType(); lingotek_keystore($entity_type, $translatable_object->getId(), 'document_id', $result->id); lingotek_keystore($entity_type, $translatable_object->getId(), 'last_uploaded', time()); } $success = TRUE; } } return $success; }
/** * Returns whether the given language is supported. * * @return * Boolean value. */ public static function isSupportedLanguage($drupal_language_code, $enabled = TRUE) { //($drupal_language_code != LANGUAGE_NONE) $supported = self::convertDrupal2Lingotek($drupal_language_code, $enabled) !== FALSE; if (!$supported) { LingotekLog::warning("Unsupported language detected: [@language]", array('@language' => $drupal_language_code)); } return $supported; }
/** * Return all segments from the database that belong to a given set ID * * @param int $set_id * * @return array * An array containing the translation sources from the locales_source table */ protected static function getAllSegments($set_id) { $max_length = variable_get('lingotek_config_max_source_length', LINGOTEK_CONFIG_MAX_SOURCE_LENGTH); //is this just to make sure there are no enormous config items or is there another reason? How often does this come into play? $lids = self::getLidsFromSets($set_id); if (empty($lids)) { return $lids; } $results = db_select('locales_source', 'ls')->fields('ls', array('lid', 'source'))->condition('lid', $lids, 'IN')->orderBy('lid')->execute(); $response = array(); while ($r = $results->fetchAssoc()) { if (strlen($r['source']) < $max_length) { $response[$r['lid']] = $r['source']; } else { LingotekLog::warning("Config item @id was not sent to Lingotek for translation because it exceeds the max length of 4096 characters.", array('@id' => $r['lid'])); // Remove it from the set in the config_map table so it doesn't get marked as uploaded or translated. self::disassociateSegments($r['lid']); } } return $response; }