Ejemplo n.º 1
0
 /**
  * Constructor.
  *
  * This is private since we want consumers to instantiate via the factory methods.
  *
  * @param $set_id
  *   A Config Set ID.
  */
 private function __construct($set_id = NULL)
 {
     $this->sid = $set_id;
     $this->set_size = LINGOTEK_CONFIG_SET_SIZE;
     $this->source_data = self::getAllSegments($this->sid);
     $this->source_meta = self::getSetMeta($this->sid);
     $this->language = language_default();
     if (!isset($this->language->lingotek_locale)) {
         // if Drupal variable 'language_default' does not exist
         $this->language->lingotek_locale = Lingotek::convertDrupal2Lingotek($this->language->language);
     }
     $this->language_targets = Lingotek::getLanguagesWithoutSource($this->language->lingotek_locale);
 }
Ejemplo n.º 2
0
 /**
  * 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_lingotek_locale = $translatable_object->getSourceLocale();
     $source_language = isset($source_lingotek_locale) && !empty($source_lingotek_locale) ? $source_lingotek_locale : Lingotek::convertDrupal2Lingotek(lingotek_get_source_language());
     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) == 'LingotekConfigChunk') {
                 $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.
                 LingotekConfigChunk::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;
 }
Ejemplo n.º 3
0
 /**
  * Constructor.
  *
  * This is private since we want consumers to instantiate via the factory methods.
  *
  * @param $chunk_id
  *   A Config Chunk ID.
  */
 private function __construct($chunk_id = NULL)
 {
     $this->cid = $chunk_id;
     $this->chunk_size = LINGOTEK_CONFIG_CHUNK_SIZE;
     $this->source_data = self::getAllSegments($this->cid);
     $this->source_meta = self::getChunkMeta($this->cid);
     $this->language = language_default();
     if (!isset($this->language->lingotek_locale)) {
         // if Drupal variable 'language_default' does not exist
         $this->language->lingotek_locale = Lingotek::convertDrupal2Lingotek($this->language->language);
     }
     $this->language_targets = Lingotek::getLanguagesWithoutSource($this->language->lingotek_locale);
     $this->min_lid = $this->getMinLid();
     $this->max_lid = $this->getMaxLid();
 }
Ejemplo n.º 4
0
 /**
  * Set the entity's language to be used by Lingotek, which will
  * sometimes be different from the stated Drupal language.
  */
 public function setLanguage($language = NULL)
 {
     if (empty($language)) {
         $drupal_locale = Lingotek::convertDrupal2Lingotek($this->entity->language);
         if (!empty($this->entity->lingotek['allow_source_overwriting']) && !empty($this->entity->lingotek['source_language_' . $drupal_locale])) {
             $language = $this->entity->lingotek['source_language_' . $drupal_locale];
         } else {
             $language = $this->entity->language;
         }
     }
     $this->language = $language;
     $this->locale = Lingotek::convertDrupal2Lingotek($this->language);
     $this->language_targets = Lingotek::getLanguagesWithoutSource($this->locale);
 }
Ejemplo n.º 5
0
 public static function getDirtyChunkLids()
 {
     // return the list of all lids from the locale_source table *not* fully translated
     $source_language = language_default();
     if (!isset($source_language->lingotek_locale)) {
         $source_language->lingotek_locale = Lingotek::convertDrupal2Lingotek($source_language->language);
     }
     $lingotek_codes = Lingotek::getLanguagesWithoutSource($source_language->lingotek_locale);
     if (!count($lingotek_codes)) {
         LingotekLog::error('No languages configured for this Lingotek account.', array());
         return array();
     }
     // get the drupal language for each associated lingotek locale
     $drupal_codes = array();
     foreach ($lingotek_codes as $lc) {
         $drupal_codes[] = Lingotek::convertLingotek2Drupal($lc);
     }
     // get the list of all segments that need updating
     // that belong to the textgroups the user wants translated
     $textgroups = array_merge(array(-1), LingotekConfigChunk::getTextgroupsForTranslation());
     $max_length = variable_get('lingotek_config_max_source_length', LINGOTEK_CONFIG_MAX_SOURCE_LENGTH);
     $query = db_select('{locales_source}', 'ls');
     $query->fields('ls', array('lid'))->condition('ls.source', '', '!=')->condition('ls.lid', self::getQueryCompletedConfigTranslations($drupal_codes), 'NOT IN')->where('length(ls.source) < ' . (int) $max_length);
     if (in_array('misc', $textgroups)) {
         $or = db_or();
         $or->condition('ls.textgroup', $textgroups, 'IN');
         $or->where("ls.textgroup NOT IN ('default','menu','taxonomy','views','blocks','field')");
         $query->condition($or);
     } else {
         $query->condition('ls.textgroup', $textgroups, 'IN');
     }
     return $query->execute()->fetchCol();
 }
Ejemplo n.º 6
0
 /**
  * Gets the comment-specific parameters for use in a createContentDocumentWithTargets API call.
  *
  * @param LingotekComment
  *   The comment entity to be translated.
  *
  * @return array
  *   An array of API parameter values.
  */
 protected function getCommentCreateWithTargetsParams(LingotekComment $comment)
 {
     $target_locales = Lingotek::availableLanguageTargets("lingotek_locale");
     $parameters = array('projectId' => variable_get('lingotek_project', NULL), 'documentName' => 'comment - ' . $comment->cid, 'documentDesc' => 'comment ' . $comment->cid . ' on node ' . $comment->nid, 'format' => $this->xmlFormat(), 'applyWorkflow' => 'true', 'workflowId' => variable_get('lingotek_translate_comments_workflow_id', NULL), 'sourceLanguage' => Lingotek::convertDrupal2Lingotek($comment->language), 'tmVaultId' => variable_get('lingotek_vault', 1), 'content' => $comment->documentLingotekXML(), 'targetAsJSON' => drupal_json_encode(array_values($target_locales)), 'note' => url('node/' . $comment->nid, array('absolute' => TRUE, 'alias' => TRUE)));
     $this->addAdvancedParameters($parameters, $comment);
     return $parameters;
 }
Ejemplo n.º 7
0
 public function getSourceLocale()
 {
     return Lingotek::convertDrupal2Lingotek($this->entity->language);
 }