/** * @param int $job_id * @param string $xliff_version * * @return string */ private function get_xliff_file($job_id, $xliff_version = WPML_XLIFF_DEFAULT_VERSION) { $xliff = new WPML_TM_xliff($xliff_version); return $xliff->generate_job_xliff($job_id); }
function send_strings_to_translation_service($string_ids, $target_language, $basket_name, $translator_id) { global $wpdb; // get all the untranslated strings $untranslated = array(); foreach ($string_ids as $st_id) { $untranslated[] = $st_id; } if (sizeof($untranslated) > 0) { $project = TranslationProxy::get_current_project(); $strings = array(); $word_count = 0; $source_language = $this->get_strings_language(); foreach ($untranslated as $string_id) { $string_data_query = "SELECT id, context, name, value FROM {$wpdb->prefix}icl_strings WHERE id=%d"; $string_data_prepare = $wpdb->prepare($string_data_query, $string_id); $string_data = $wpdb->get_row($string_data_prepare); $word_count += $this->estimate_word_count($string_data->value, $source_language); $strings[] = $string_data; } $xliff = new WPML_TM_xliff(); $file = $xliff->get_strings_xliff_file($strings, $source_language, $target_language); $title = "String Translations"; $cms_id = ''; $url = ''; $timestamp = date('Y-m-d H:i:s'); if (TranslationProxy::is_batch_mode()) { $res = $project->send_to_translation_batch_mode($file, $title, $cms_id, $url, $source_language, $target_language, $word_count); } else { $res = $project->send_to_translation($file, $title, $cms_id, $url, $source_language, $target_language, $word_count); } if ($res) { foreach ($strings as $string_data) { $batch_id = TranslationProxy_Batch::update_translation_batch($basket_name); $translation_service = TranslationProxy_Service::get_translator_data_from_wpml($translator_id); $added = icl_add_string_translation($string_data->id, $target_language, null, ICL_TM_WAITING_FOR_TRANSLATOR, $translation_service['translator_id'], $translation_service['translation_service'], $batch_id); if ($added) { $data = array('rid' => $res, 'string_translation_id' => $added, 'timestamp' => $timestamp, 'md5' => md5($string_data->value)); $wpdb->insert($wpdb->prefix . 'icl_string_status', $data); //insert rid } else { $this->add_message(sprintf(__('Unable to add "%s" string in tables', 'sitepress'), $string_data->name), 'error'); return 0; } } $wpdb->insert($wpdb->prefix . 'icl_core_status', array('rid' => $res, 'module' => '', 'origin' => $source_language, 'target' => $target_language, 'status' => CMS_REQUEST_WAITING_FOR_PROJECT_CREATION)); if ($project->errors && count($project->errors)) { $res['errors'] = $project->errors; } return $res; } } return 0; }
function process_translated_string($translation_proxy_job_id, $language) { $project = TranslationProxy::get_current_project(); $translation = $project->fetch_translation($translation_proxy_job_id); $translation = apply_filters('icl_data_from_pro_translation', $translation); $ret = false; $xliff = new WPML_TM_xliff(); $translation = $xliff->get_strings_xliff_translation($translation); if ($translation) { $ret = icl_translation_add_string_translation($translation_proxy_job_id, $translation, $language); if ($ret) { $project->update_job($translation_proxy_job_id); } } return $ret; }
function to_xliff_file() { $xliff = new WPML_TM_xliff(); return $xliff->get_job_xliff_file($this->get_id()); }