Changeset 12527 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-suggestions/inc/routes/class-translation-memory.php
- Timestamp:
- 04/05/2023 07:33:49 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-suggestions/inc/routes/class-translation-memory.php
r12513 r12527 12 12 13 13 public function get_suggestions( $project_path, $locale_slug, $set_slug ) { 14 $type = 'Translation'; 14 15 $original_id = gp_get( 'original' ); 15 16 $translation_id = gp_get( 'translation', 0 ); … … 39 40 } 40 41 41 $suggestions = Translation_Memory_Client::query( $original->singular, $locale ); 42 $suggestions = Translation_Memory_Client::query( $original->singular, $locale ); 43 44 if ( is_wp_error( $suggestions ) ) { 45 wp_send_json_error( $suggestions->get_error_code() ); 46 } 47 48 wp_send_json_success( 49 gp_tmpl_get_output( 50 'translation-memory-suggestions', 51 compact( 'suggestions', 'type' ), 52 PLUGIN_DIR . '/templates/' 53 ) 54 ); 55 } 56 57 public function get_openai_suggestions( $project_path, $locale_slug, $set_slug ) { 58 $type = 'OpenAI'; 59 $original_id = gp_get( 'original' ); 60 $translation_id = gp_get( 'translation', 0 ); 61 $nonce = gp_get( 'nonce' ); 62 $gp_default_sort = get_user_option( 'gp_default_sort' ); 63 $external_services_exclude_some_status = gp_array_get( $gp_default_sort, 'external_services_exclude_some_status', 0 ); 64 $translation = null; 65 $suggestions = array(); 66 67 if ( ! wp_verify_nonce( $nonce, 'translation-memory-suggestions-' . $original_id ) ) { 68 wp_send_json_error( 'invalid_nonce' ); 69 } 70 71 if ( empty( $original_id ) ) { 72 wp_send_json_error( 'no_original' ); 73 } 74 75 $original = GP::$original->get( $original_id ); 76 if ( ! $original ) { 77 wp_send_json_error( 'invalid_original' ); 78 } 79 42 80 $current_set_slug = 'default'; 43 81 $locale_glossary_translation_set = GP::$translation_set->by_project_id_slug_and_locale( 0, $current_set_slug, $locale_slug ); … … 49 87 } 50 88 if ( ! $translation || ( 'current' != $translation->status && 'rejected' != $translation->status && 'old' != $translation->status ) ) { 51 $openai_suggestions = $this->get_openai_suggestion( $original->singular, $locale_slug, $locale_glossary ); 52 $deepl_suggestions = $this->get_deepl_suggestion( $original->singular, $locale_slug, $set_slug ); 89 $suggestions = $this->get_openai_suggestion( $original->singular, $locale_slug, $locale_glossary ); 53 90 } 54 91 } else { 55 $openai_suggestions = $this->get_openai_suggestion( $original->singular, $locale_slug, $locale_glossary ); 56 $deepl_suggestions = $this->get_deepl_suggestion( $original->singular, $locale_slug, $set_slug ); 57 } 58 59 if ( is_wp_error( $suggestions ) ) { 60 wp_send_json_error( $suggestions->get_error_code() ); 61 } 62 63 wp_send_json_success( gp_tmpl_get_output( 'translation-memory-suggestions', compact( 'suggestions', 'openai_suggestions', 'deepl_suggestions' ), PLUGIN_DIR . '/templates/' ) ); 92 $suggestions = $this->get_openai_suggestion( $original->singular, $locale_slug, $locale_glossary ); 93 } 94 95 wp_send_json_success( 96 gp_tmpl_get_output( 97 'translation-memory-suggestions', 98 compact( 'suggestions', 'type' ), 99 PLUGIN_DIR . '/templates/' 100 ) 101 ); 102 } 103 104 public function get_deepl_suggestions( $project_path, $locale_slug, $set_slug ) { 105 $type = 'DeepL'; 106 $original_id = gp_get( 'original' ); 107 $translation_id = gp_get( 'translation', 0 ); 108 $nonce = gp_get( 'nonce' ); 109 $gp_default_sort = get_user_option( 'gp_default_sort' ); 110 $external_services_exclude_some_status = gp_array_get( $gp_default_sort, 'external_services_exclude_some_status', 0 ); 111 $translation = null; 112 $suggestions = array(); 113 114 if ( ! wp_verify_nonce( $nonce, 'translation-memory-suggestions-' . $original_id ) ) { 115 wp_send_json_error( 'invalid_nonce' ); 116 } 117 118 if ( empty( $original_id ) ) { 119 wp_send_json_error( 'no_original' ); 120 } 121 122 $original = GP::$original->get( $original_id ); 123 if ( ! $original ) { 124 wp_send_json_error( 'invalid_original' ); 125 } 126 127 $locale = $locale_slug; 128 if ( 'default' !== $set_slug ) { 129 $locale .= '_' . $set_slug; 130 } 131 132 if ( $external_services_exclude_some_status ) { 133 if ( $translation_id > 0 ) { 134 $translation = GP::$translation->get( $translation_id ); 135 } 136 if ( ! $translation || ( 'current' != $translation->status && 'rejected' != $translation->status && 'old' != $translation->status ) ) { 137 $suggestions = $this->get_deepl_suggestion( $original->singular, $locale_slug, $set_slug ); 138 } 139 } else { 140 $suggestions = $this->get_deepl_suggestion( $original->singular, $locale_slug, $set_slug ); 141 } 142 143 wp_send_json_success( 144 gp_tmpl_get_output( 145 'translation-memory-suggestions', 146 compact( 'suggestions', 'type' ), 147 PLUGIN_DIR . '/templates/' 148 ) 149 ); 64 150 } 65 151 … … 378 464 */ 379 465 private function update_one_external_translation( string $translation, string $suggestion, string $external_translations_used, string $external_same_translations_used ) { 380 $ sameTranslationUsed= $translation == $suggestion;466 $is_the_same_translation = $translation == $suggestion; 381 467 $gp_external_translations = get_user_option( 'gp_external_translations' ); 382 468 $translations_used = gp_array_get( $gp_external_translations, $external_translations_used, 0 ); … … 387 473 $translations_used++; 388 474 $gp_external_translations[ $external_translations_used ] = $translations_used; 389 if ( $ sameTranslationUsed) {475 if ( $is_the_same_translation ) { 390 476 if ( ! is_int( $same_translations_used ) || $same_translations_used < 0 ) { 391 477 $same_translations_used = 0;
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)