Changeset 12751 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-suggestions/inc/routes/class-translation-memory.php
- Timestamp:
- 07/21/2023 09:49:35 AM (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
r12579 r12751 483 483 484 484 /** 485 * Update s the external translations used by each user.485 * Update the number of external translations used. 486 486 * 487 487 * @return void 488 488 */ 489 public function update_external_translations() { 490 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'wporg-editor-settings' ) ) { 491 wp_send_json_error( array( 'message' => esc_html__( 'Invalid nonce.', 'glotpress' ) ), 403 ); 492 } 493 if ( ! isset( $_POST['translation'] ) ) { 494 wp_send_json_error( array( 'message' => esc_html__( 'Translation parameter is not present.', 'glotpress' ) ), 400 ); 495 } 496 if ( ! isset( $_POST['openAITranslationsUsed'] ) && ! isset( $_POST['deeplTranslationsUsed'] ) ) { 497 wp_send_json_error( array( 'message' => esc_html__( 'Translation suggested parameter is not present.', 'glotpress' ) ), 400 ); 498 } 499 if ( isset( $_POST['openAITranslationsUsed'] ) ) { 500 $this->update_one_external_translation( 501 $_POST['translation'], 502 $_POST['openAITranslationsUsed'], 503 'openai_translations_used', 504 'openai_same_translations_used' 505 ); 506 } 507 if ( isset( $_POST['deeplTranslationsUsed'] ) ) { 508 $this->update_one_external_translation( 509 $_POST['translation'], 510 $_POST['deeplTranslationsUsed'], 511 'deepl_translations_used', 512 'deepl_same_translations_used' 513 ); 514 } 515 wp_send_json_success(); 489 public function update_external_translations( $translation ) { 490 $is_source_set = isset( $_POST['externalTranslationSource'] ) && isset( $_POST['externalTranslationUsed'] ); 491 $is_request_valid = 'GP_Route_Translation' === GP::$current_route->class_name && 'translations_post' === GP::$current_route->last_method_called; 492 if ( ! $is_request_valid || ! $is_source_set || ! $translation ) { 493 return; 494 } 495 self::update_one_external_translation( 496 $translation->translation_0, 497 sanitize_text_field( $_POST['externalTranslationSource'] ), 498 sanitize_text_field( $_POST['externalTranslationUsed'] ), 499 ); 516 500 } 517 501 … … 520 504 * 521 505 * @param string $translation The translation. 506 * @param string $suggestion_source The suggestion_source. 522 507 * @param string $suggestion The suggestion. 523 * @param string $external_translations_used The external translations used.524 * @param string $external_same_translations_used The external same translations used.525 508 * 526 509 * @return void 527 510 */ 528 private function update_one_external_translation( string $translation, string $suggestion, string $external_translations_used, string $external_same_translations_used ) { 511 private static function update_one_external_translation( string $translation, string $suggestion_source, string $suggestion ) { 512 $external_translations_used = $suggestion_source . '_translations_used'; 513 $external_same_translations_used = $suggestion_source . '_same_translations_used'; 514 529 515 $is_the_same_translation = $translation == $suggestion; 530 516 $gp_external_translations = get_user_option( 'gp_external_translations' );
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)