当前位置: 首页>>代码示例>>PHP>>正文


PHP TranslationProxy::is_batch_mode方法代码示例

本文整理汇总了PHP中TranslationProxy::is_batch_mode方法的典型用法代码示例。如果您正苦于以下问题:PHP TranslationProxy::is_batch_mode方法的具体用法?PHP TranslationProxy::is_batch_mode怎么用?PHP TranslationProxy::is_batch_mode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TranslationProxy的用法示例。


在下文中一共展示了TranslationProxy::is_batch_mode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: send_basket_commit

 public function send_basket_commit()
 {
     $has_remote_translators = false;
     try {
         $response = false;
         $errors = array();
         if (TranslationProxy::is_batch_mode()) {
             $project = TranslationProxy::get_current_project();
             $translators = $_POST['translators'];
             $has_remote_translators = false;
             if (is_array($translators)) {
                 foreach ($translators as $translator) {
                     if (!TranslationProxy_Service::is_local_translator($translator)) {
                         $has_remote_translators = true;
                         break;
                     }
                 }
             } else {
                 $has_remote_translators = true;
             }
             if ($project && $has_remote_translators) {
                 $response = $project->commit_batch_job();
                 if (!empty($project->errors)) {
                     $response = false;
                 }
             } else {
                 //Local translation only: return true
                 $response = true;
             }
         }
         if ($response) {
             $is_error = false;
             TranslationProxy_Basket::delete_all_items_from_basket();
             $service_name = TranslationProxy::get_current_service_name();
             if (isset($has_remote_translators) && $has_remote_translators) {
                 $response->call_to_action = '<strong>' . sprintf(__('You have sent items to %s. Please check if additional steps are required on their end', 'wpml-translation-management'), $service_name) . '</strong>';
             }
         } else {
             $response = false;
             $is_error = true;
             if (isset($project) && $project) {
                 $errors = $project->errors;
             }
         }
     } catch (Exception $e) {
         $response = false;
         $is_error = true;
         $errors[] = $e->getMessage();
     }
     $result = array('result' => $response, 'is_error' => $is_error, 'errors' => $errors);
     if (!empty($errors)) {
         $this->rollback_basket_commit();
         wp_send_json_error($result);
     } else {
         wp_send_json_success($result);
     }
 }
开发者ID:ryuqing,项目名称:cake,代码行数:57,代码来源:wpml-basket-tab-ajax.class.php

示例2: send_strings_to_translation_service

 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;
 }
开发者ID:crazyyy,项目名称:octagram,代码行数:54,代码来源:wpml-string-translation.class.php

示例3: send_post

 /**
  * @param WP_Post|WPML_Package $post
  * @param                      $target_languages
  * @param int                  $translator_id
  * @param                      $job_id
  *
  * @return bool|int
  */
 function send_post($post, $target_languages, $translator_id, $job_id)
 {
     global $sitepress, $sitepress_settings, $wpdb, $iclTranslationManagement;
     $this->maybe_init_translation_management($iclTranslationManagement);
     if (is_numeric($post)) {
         $post = get_post($post);
     }
     if (!$post) {
         return false;
     }
     $post_id = $post->ID;
     $post_type = $post->post_type;
     $element_type_prefix = $iclTranslationManagement->get_element_type_prefix_from_job_id($job_id);
     $element_type = $element_type_prefix . '_' . $post_type;
     $err = false;
     $res = false;
     $source_language = $sitepress->get_language_for_element($post_id, $element_type);
     if (empty($target_languages)) {
         return false;
     }
     // Make sure the previous request is complete.
     // Only send if it needs update
     foreach ($target_languages as $target_language) {
         if ($target_language == $source_language) {
             continue;
         }
         $translation = $this->tmg->get_element_translation($post_id, $target_language, $element_type);
         if (!$translation) {
             // translated the first time
             $err = true;
         }
         if (!$err && ($translation->needs_update || $translation->status == ICL_TM_NOT_TRANSLATED || $translation->status == ICL_TM_WAITING_FOR_TRANSLATOR)) {
             $project = TranslationProxy::get_current_project();
             if ($post_type == 'page') {
                 $post_url = site_url() . '?page_id=' . $post_id;
             } else {
                 $post_url = site_url() . '?p=' . $post_id;
             }
             if ($iclTranslationManagement->is_external_type($element_type_prefix)) {
                 $post_url = apply_filters('wpml_external_item_url', $post_url, $post_id);
             }
             if ($sitepress->get_setting('tm_block_retranslating_terms')) {
                 WPML_Translation_Job_Terms::set_translated_term_values($job_id, true);
             }
             $xliff = new WPML_TM_xliff();
             $file = $xliff->get_job_xliff_file($job_id);
             $title = $post->post_title;
             $cms_id = $this->build_cms_id($post_id, $post_type, $source_language, $target_language, $job_id);
             $url = $post_url;
             $word_count = self::estimate_total_word_count($post, $source_language);
             $note = isset($note) ? $note : '';
             $is_update = intval(!empty($translation->element_id));
             try {
                 if (TranslationProxy::is_batch_mode()) {
                     $res = $project->send_to_translation_batch_mode($file, $title, $cms_id, $url, $source_language, $target_language, $word_count, $translator_id, $note, $is_update);
                 } else {
                     $res = $project->send_to_translation($file, $title, $cms_id, $url, $source_language, $target_language, $word_count, $translator_id, $note, $is_update);
                 }
             } catch (Exception $err) {
                 // The translation entry will be removed
                 $res = 0;
             }
             if ($res) {
                 $this->tmg->update_translation_status(array('translation_id' => $translation->translation_id, 'status' => ICL_TM_IN_PROGRESS, 'needs_update' => 0));
             } else {
                 $this->enqueue_project_errors($project);
                 $previous_state = $wpdb->get_var($wpdb->prepare("SELECT _prevstate FROM {$wpdb->prefix}icl_translation_status WHERE translation_id=%d", $translation->translation_id));
                 if (!empty($previous_state)) {
                     $previous_state = unserialize($previous_state);
                     $data = array('status' => $previous_state['status'], 'translator_id' => $previous_state['translator_id'], 'needs_update' => $previous_state['needs_update'], 'md5' => $previous_state['md5'], 'translation_service' => $previous_state['translation_service'], 'translation_package' => $previous_state['translation_package'], 'timestamp' => $previous_state['timestamp'], 'links_fixed' => $previous_state['links_fixed']);
                     $data_where = array('translation_id' => $translation->translation_id);
                     $wpdb->update($wpdb->prefix . 'icl_translation_status', $data, $data_where);
                 } else {
                     $data = array('status' => ICL_TM_NOT_TRANSLATED, 'needs_update' => 0);
                     $data_where = array('translation_id' => $translation->translation_id);
                     $wpdb->update($wpdb->prefix . 'icl_translation_status', $data, $data_where);
                 }
                 $err = true;
             }
         }
         // if needs translation
     }
     // foreach target lang
     return $err ? false : $res;
     //last $ret
 }
开发者ID:ryuqing,项目名称:cake,代码行数:94,代码来源:wpml-pro-translation.class.php

示例4: send_post

 /**
  * @param WP_Post|WPML_Package $post
  * @param                      $target_languages
  * @param int                  $translator_id
  * @param                      $job_id
  *
  * @return bool|int
  */
 function send_post($post, $target_languages, $translator_id, $job_id)
 {
     global $sitepress, $iclTranslationManagement;
     $this->maybe_init_translation_management($iclTranslationManagement);
     if (is_numeric($post)) {
         $post = get_post($post);
     }
     if (!$post) {
         return false;
     }
     $post_id = $post->ID;
     $post_type = $post->post_type;
     $element_type_prefix = $iclTranslationManagement->get_element_type_prefix_from_job_id($job_id);
     $element_type = $element_type_prefix . '_' . $post_type;
     $err = false;
     $res = false;
     $source_language = $sitepress->get_language_for_element($post_id, $element_type);
     $target_language = is_array($target_languages) ? end($target_languages) : $target_languages;
     if (empty($target_language) || $target_language === $source_language) {
         return false;
     }
     $translation = $this->tmg->get_element_translation($post_id, $target_language, $element_type);
     if (!$translation) {
         // translated the first time
         $err = true;
     }
     if (!$err && ($translation->needs_update || $translation->status == ICL_TM_NOT_TRANSLATED || $translation->status == ICL_TM_WAITING_FOR_TRANSLATOR)) {
         $tp_networking = wpml_tm_load_tp_networking();
         $project = $tp_networking->get_current_project();
         if ($iclTranslationManagement->is_external_type($element_type_prefix)) {
             $job_object = new WPML_External_Translation_Job($job_id);
         } else {
             $job_object = new WPML_Post_Translation_Job($job_id);
             $job_object->load_terms_from_post_into_job();
         }
         list($err, $project, $res) = $job_object->send_to_tp($project, TranslationProxy::is_batch_mode(), $translator_id, $this->cms_id_helper, $this->tmg);
         if ($err) {
             $this->enqueue_project_errors($project);
         }
     }
     return $err ? false : $res;
     //last $ret
 }
开发者ID:Junaid-Farid,项目名称:gocnex,代码行数:51,代码来源:wpml-pro-translation.class.php


注:本文中的TranslationProxy::is_batch_mode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。