public static function languages_map($service)
 {
     $languages_map = array();
     $languages = TranslationProxy_Api::proxy_request("/services/{$service->id}/language_identifiers.json");
     foreach ($languages as $language) {
         $languages_map[$language->iso_code] = $language->value;
     }
     return $languages_map;
 }
 /**
  * @param int|bool $service_id If not given, will use the current service ID (if any)
  * @param bool $force_reload Force reload custom fields from Translation Service
  *
  * @throws TranslationProxy_Api_Error
  * @throws InvalidArgumentException
  * @return array|mixed|null|string
  */
 public static function get_custom_fields($service_id = false, $force_reload = false)
 {
     if (!$service_id) {
         $service_id = self::get_current_service_id();
     }
     if (!$service_id) {
         return false;
     }
     $translation_service = self::get_current_service();
     if ($translation_service && !$force_reload) {
         return isset($translation_service->custom_fields) ? $translation_service->custom_fields : false;
     }
     $params = array('service_id' => $service_id);
     return TranslationProxy_Api::proxy_request('/services/{service_id}/custom_fields.json', $params);
 }
Example #3
0
 public static function get_extra_fields_remote($project = null)
 {
     if (!$project) {
         $project = self::get_current_project();
     }
     $api_version = TranslationProxy_Api::API_VERSION;
     $params = array('accesskey' => $project->access_key, 'api_version' => $api_version, 'project_id' => $project->id);
     return TranslationProxy_Api::proxy_request('/projects/{project_id}/extra_fields.json', $params);
 }
 public function get_extra_fields_remote($project)
 {
     $params = array('accesskey' => $project->access_key, 'api_version' => self::API_VERSION, 'project_id' => $project->id);
     return TranslationProxy_Api::proxy_request('/projects/{project_id}/extra_fields.json', $params);
 }
 /**
  * @param string    $state
  * @param null|bool $include_archived `null` ignores this argument, `true` or `false` filters by this argument
  *
  * @return mixed
  */
 private function get_jobs($state = 'any', $include_archived = null)
 {
     $batch = TranslationProxy_Basket::get_batch_data();
     $params = array('project_id' => $this->id, 'accesskey' => $this->access_key, 'state' => $state);
     if (null !== $include_archived) {
         $params['archived'] = $include_archived;
     }
     if ($batch) {
         $params['batch_id'] = $batch ? $batch->id : false;
         return TranslationProxy_Api::proxy_request('/batches/{batch_id}/jobs.json', $params);
     } else {
         //FIXME: remove this once TP will accept the TP Project ID: https://icanlocalize.basecamphq.com/projects/11113143-translation-proxy/todo_items/182251206/comments
         $params['project_id'] = $this->id;
     }
     try {
         return TranslationProxy_Api::proxy_request('/jobs.json', $params);
     } catch (Exception $ex) {
         $this->add_error($ex->getMessage());
         return false;
     }
 }
 /**
  * @param string $state
  *
  * @return mixed
  */
 private function get_jobs($state = 'any')
 {
     $batch = TranslationProxy_Basket::get_batch_data();
     $params = array('project_id' => $this->id, 'accesskey' => $this->access_key, 'state' => $state);
     if ($batch) {
         $params['batch_id'] = $batch ? $batch->id : false;
         return TranslationProxy_Api::proxy_request('/batches/{batch_id}/jobs.json', $params);
     } else {
         //FIXME: remove this once TP will accept the TP Project ID: https://icanlocalize.basecamphq.com/projects/11113143-translation-proxy/todo_items/182251206/comments
         $params['project_id'] = $this->id;
     }
     return TranslationProxy_Api::proxy_request('/jobs.json', $params);
 }
 public function update_job($job_id, $url = null, $state = 'delivered')
 {
     $params = array('job_id' => $job_id, 'project_id' => $this->id, 'accesskey' => $this->access_key, 'job' => array('state' => $state));
     if ($url) {
         $params['job']['url'] = $url;
     }
     try {
         TranslationProxy_Api::proxy_request("/jobs/{job_id}.json", $params, 'PUT');
         return true;
     } catch (Exception $ex) {
         $this->add_error($ex->getMessage());
         return false;
     }
 }
 public function enqueue_migration_in_tp()
 {
     global $sitepress;
     remove_filter('otgs_translation_get_services', 'filter_tp_services');
     $site_id = $sitepress->get_setting('site_id');
     $access_key = $sitepress->get_setting('access_key');
     $delivery = wpml_get_setting_filter(false, 'translation_pickup_method');
     $delivery = $delivery === 'polling' ? 'polling' : 'xmlrpc';
     $service = TranslationProxy_Service::get_service($this->get_icl_service_id());
     $params = array('project' => array('ts_accesskey' => $access_key, 'external_id' => $site_id, 'delivery_method' => $delivery, 'url' => get_option('siteurl'), 'name' => get_option('blogname'), 'description' => get_option('blogdescription'), 'suid' => isset($service->suid) ? $service->suid : ""));
     $project = false;
     $error_data = false;
     try {
         $response = TranslationProxy_Api::proxy_request('/projects/migrate.json', $params, 'POST');
         if (isset($response->project)) {
             $project = (array) $response->project;
             $project_index = $this->icl_project_hash_key();
             $projects = TranslationProxy::get_translation_projects();
             $projects[$project_index] = $project;
             icl_set_setting('icl_translation_projects', $projects, true);
             icl_set_setting('translation_service', TranslationProxy_Service::get_service($this->get_icl_service_id()), true);
         }
     } catch (Exception $e) {
         $error_data = $params;
     }
     if (!$error_data) {
         $this->move_finished_jobs_to_batch();
         if (defined('ICL_DEBUG_MODE') && ICL_DEBUG_MODE) {
             $this->regenerate_wrong_service_data();
         }
     }
     return array($project, $error_data);
 }