Making WordPress.org

Changeset 12629


Ignore:
Timestamp:
06/07/2023 08:07:12 AM (3 years ago)
Author:
akirk
Message:

Translate: allow switching on thin ajax request via flag

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/includes/class-gp-openai-review.php

    r12626 r12629  
    2525
    2626                if ( empty( trim( $openai_key ) ) ) {
    27                         return array();
     27                        return array(
     28                                'status' => 404,
     29                                'error' => 'No OpenAI Key defined',
     30                        );
    2831                }
    29                 $openai_temperature = 0;
    3032
    3133                $openai_query .= 'For the english text  "' . $original . '", is "' . $translation . '" a correct translation in ' . $language . '?';
     
    5557                                                'n'           => 1,
    5658                                                'messages'    => $messages,
    57                                                 'temperature' => $openai_temperature,
    5859                                        )
    5960                                ),
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/includes/class-gp-translation-helpers.php

    r12626 r12629  
    397397                gp_enqueue_script( 'gp-comment-feedback-js' );
    398398
     399                $gp_locale = GP_Locales::by_field( 'slug', $translation_set['locale_slug'] );
    399400                wp_localize_script(
    400401                        'gp-comment-feedback-js',
     
    404405                                'nonce'           => wp_create_nonce( 'gp_comment_feedback' ),
    405406                                'locale_slug'     => $translation_set['locale_slug'],
     407                                'language'        => $gp_locale ? $gp_locale->english_name : 'Unknown',
     408                                'has_openai_key'  => !! apply_filters( 'gp_get_openai_key', null ),
    406409                                'comment_reasons' => Helper_Translation_Discussion::get_comment_reasons( $translation_set['locale_slug'] ),
    407410                        )
     
    453456
    454457                $openai_response = GP_OpenAI_Review::get_openai_review( $original, $translation, $language, $glossary, $is_retry );
    455 
     458                if ( isset( $openai_response['error'] ) ) {
     459                        wp_send_json_error( $openai_response );
     460                }
    456461                wp_send_json_success( $openai_response );
    457462        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/js/editor.js

    r12626 r12629  
    2626                focusedRowId = rowId;
    2727                loadTabsAndDivs( tr );
    28                 if ( $gp_editor_options.can_approve && ( 'waiting' === translation_status || 'fuzzy' === translation_status ) ) {
     28                if ( $gp_comment_feedback_settings.has_openai_key && $gp_editor_options.can_approve && ( 'waiting' === translation_status || 'fuzzy' === translation_status ) ) {
    2929                        fetchOpenAIReviewResponse( rowId, tr, false );
     30                } else {
     31                        tr.find( '.openai-review' ).hide();
    3032                }
    3133        } );
     
    274276                        {
    275277                                type: 'POST',
    276                                 url: '/wp-content/plugins/wporg-gp-translation-suggestions/ajax-fetch-openai-review.php',
     278                                url: typeof window.useThinFetch !== 'undefined' && window.useThinFetch ? '/wp-content/plugins/wporg-gp-translation-suggestions/ajax-fetch-openai-review.php' : $gp_comment_feedback_settings.url,
    277279                                data: data,
    278280                        }
     
    280282                        function( response ) {
    281283                                currentRow.find( '.openai-review .suggestions__loading-indicator' ).hide();
    282                                 if ( 200 === response.data.status ) {
     284                                if ( response.success ) {
    283285                                        currentRow.find( '.openai-review .auto-review-result' ).html( '<h4>Review by ChatGPT' ).append( $( '<span/>' ).text( response.data.review + ' (' + response.data.time_taken.toFixed( 2 ) + 's)' ) );
     286                                } else if ( 404 === response.data.status ) {
     287                                        currentRow.find( '.openai-review' ).hide();
     288                                        return;
    284289                                } else {
    285290                                        currentRow.find( '.openai-review .auto-review-result' ).text( 'Error ' + response.data.status + ' : ' + response.data.error );
     
    291296                                /* eslint no-console: ["error", { allow: ["error"] }] */
    292297                                console.error( data );
    293                                 msg = 'An error has occurred';
    294                                 if ( xhr.responseText ) {
    295                                         msg += ': ' + xhr.responseText;
    296                                 }
    297                                 msg += '. Please, take a screenshot of the output in the browser console, send it to the developers, and reload the page to see if it works.';
    298                                 $gp.notices.error( msg );
    299298                        }
    300299                );
Note: See TracChangeset for help on using the changeset viewer.