Making WordPress.org

Changeset 12656


Ignore:
Timestamp:
06/14/2023 10:54:45 AM (2 years ago)
Author:
akirk
Message:

Translate: sync gp-translation-helpers from git

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

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/css/discussion.css

    r12624 r12656  
    197197    padding: 8px;
    198198}
    199 .meta summary.feedback-summary{
    200     font-size: 1.2em;
     199.meta summary.feedback-summary, .meta summary.chatgpt-summary{
     200    font-size: 1.1em;
    201201    font-weight: bold;
    202202    padding: 7px 0;
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/helpers-assets/js/translation-discussion.js

    r11837 r12656  
    22jQuery( function( $ ) {
    33    $( document ).on( 'click', '.helper-translation-discussion .comments-selector a', function( e ) {
    4         var $comments, $selector;
    5 
    64        e.preventDefault();
    75        $( '.comments-selector a' ).removeClass( 'active-link' );
    86        $( this ).addClass( 'active-link' );
    9         $comments = jQuery( e.target ).parents( 'h6' ).next( '.discussion-list' );
    10         $selector = $( e.target ).data( 'selector' );
     7        const $comments = jQuery( e.target ).parents( 'h6' ).next( '.discussion-list' );
     8        const $selector = $( e.target ).data( 'selector' );
    119        if ( 'all' === $selector ) {
    1210            $comments.children().show();
     
    2321
    2422    function createShadowPost( formdata, submitComment ) {
    25         var data = {
     23        const data = {
    2624            action: 'create_shadow_post',
    2725            data: formdata,
     
    3331                type: 'POST',
    3432                url: wpApiSettings.admin_ajax_url,
    35                 data: data,
    36             }
     33                data,
     34            },
    3735        ).done(
    3836            function( response ) {
    3937                formdata.post = response.data;
    4038                submitComment( formdata );
    41             }
     39            },
    4240        );
    4341    }
    4442
    4543    $( document ).on( 'submit', '.helper-translation-discussion .comment-form', function( e ) {
    46         var $commentform = $( e.target );
    47         var postId = $commentform.attr( 'id' ).split( '-' )[ 1 ];
    48         var submitComment = function( formdata ) {
     44        const $commentform = $( e.target );
     45        const postId = $commentform.attr( 'id' ).split( '-' )[ 1 ];
     46        const submitComment = function( formdata ) {
    4947            $.ajax( {
    5048                url: wpApiSettings.root + 'wp/v2/comments',
    5149                method: 'POST',
    52                 beforeSend: function( xhr ) {
     50                beforeSend( xhr ) {
    5351                    xhr.setRequestHeader( 'X-WP-Nonce', wpApiSettings.nonce );
    5452                },
     
    6563        };
    6664
    67         var formdata = {
     65        const formdata = {
    6866            content: $commentform.find( 'textarea[name=comment]' ).val(),
    6967            parent: $commentform.find( 'input[name=comment_parent]' ).val(),
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/includes/class-gp-openai-review.php

    r12629 r12656  
    2727            return array(
    2828                'status' => 404,
    29                 'error' => 'No OpenAI Key defined',
     29                'error' => 'no-openai-key',
    3030            );
    3131        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/js/editor.js

    r12635 r12656  
    1 /* global $gp, $gp_translation_helpers_editor, wpApiSettings, $gp_comment_feedback_settings, console, $gp_editor_options, EventSource */
     1/* global $gp, $gp_translation_helpers_editor, wpApiSettings, $gp_comment_feedback_settings, $gp_editor_options, fetch, TextDecoderStream */
    22/* eslint camelcase: "off" */
    33jQuery( function( $ ) {
     
    6969                url: wpApiSettings.admin_ajax_url,
    7070                data,
    71             }
     71            },
    7272        ).done(
    7373            function( response ) {
    7474                formdata.post = response.data;
    7575                submitComment( formdata );
    76             }
     76            },
    7777        );
    7878    }
     
    339339            index,
    340340            fieldLength,
    341             lineLength
     341            lineLength,
    342342        ) {
    343343            if ( lineLength === 0 ) {
     
    409409                response_span.text( event.value );
    410410            } else if ( event.type === 'reconnect-interval' ) {
    411                 console.log( 'We should set reconnect interval to %d milliseconds', event.value );
     411                // console.log( 'We should set reconnect interval to %d milliseconds', event.value );
    412412            }
    413413        } );
    414414
    415         let response = await fetch(
     415        const response = await fetch(
    416416            'https://api.openai.com/v1/chat/completions',
    417417            {
     
    422422                method: 'POST',
    423423                body: JSON.stringify( request ),
    424             }
     424            },
    425425        );
    426         const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
    427 
    428         while (true) {
     426        const reader = response.body.pipeThrough( new TextDecoderStream() ).getReader();
     427
     428        while ( true ) {
    429429            const { value, done } = await reader.read();
    430             if ( done ) break;
     430            if ( done ) {
     431                break;
     432            }
    431433            parser.feed( value );
    432434        }
     
    438440     * @param {string}  rowId      The row-id attribute of the current row.
    439441     * @param {string}  currentRow The current row.
     442     * @param {boolean} isRetry    This is a retry.
    440443     */
    441444    function fetchOpenAIReviewResponse( rowId, currentRow, isRetry ) {
     
    443446        const original_str = currentRow.find( '.original' );
    444447        let glossary_prompt = '';
    445         let result = '';
    446448
    447449        $.each( $( original_str ).find( '.glossary-word' ), function( k, word ) {
     
    468470        currentRow.find( '.openai-review .suggestions__loading-indicator' ).hide();
    469471        currentRow.find( '.openai-review .auto-review-result' ).html( '<h4>Review by ChatGPT' ).append( '<span style="white-space: pre-line">' );
    470         invokeChatGPT( messages, currentRow.find( '.openai-review .auto-review-result span' ) ).then(()=>currentRow.find( '.openai-review .auto-review-result' ).append( ' <a href="#" class="retry-auto-review">Retry</a>' ));
     472        invokeChatGPT( messages, currentRow.find( '.openai-review .auto-review-result span' ) ).then( () => currentRow.find( '.openai-review .auto-review-result' ).append( ' <a href="#" class="retry-auto-review">Retry</a>' ) );
    471473    }
    472474} );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/js/reject-feedback.js

    r12435 r12656  
    33    $( document ).ready(
    44        function() {
    5             var rowIds = [];
    6             var translationIds = [];
    7             var originalIds = [];
    8             var bulkTranslationStatus = [];
    9             var translationStatuses = {};
    10             var statusIndex = 0;
    11             var modalFeedbackForm =
     5            let rowIds = [];
     6            const translationIds = [];
     7            const originalIds = [];
     8            const bulkTranslationStatus = [];
     9            const translationStatuses = {};
     10            let statusIndex = 0;
     11            const modalFeedbackForm =
    1212            '<div id="reject-feedback-form" style="display:none;">' +
    1313            '<form>' +
     
    3232                    rowIds = $( 'input:checked', $( 'table#translations th.checkbox' ) ).map(
    3333                        function() {
    34                             var selectedRow = $( this ).parents( 'tr.preview' );
    35                             var translationStatus = '';
     34                            const selectedRow = $( this ).parents( 'tr.preview' );
     35                            let translationStatus = '';
    3636
    3737                            if ( ( selectedRow.length ) && ( ! selectedRow.hasClass( 'untranslated' ) ) ) {
     
    4242                            $( this ).prop( 'checked', false );
    4343                            return null;
    44                         }
     44                        },
    4545                    ).get();
    4646
    4747                    rowIds.forEach(
    4848                        function( rowId ) {
    49                             var originalId = $gp.editor.original_id_from_row_id( rowId );
    50                             var translationId = $gp.editor.translation_id_from_row_id( rowId );
     49                            const originalId = $gp.editor.original_id_from_row_id( rowId );
     50                            const translationId = $gp.editor.translation_id_from_row_id( rowId );
    5151
    5252                            if ( originalId && translationId ) {
     
    5656                            }
    5757                            statusIndex++;
    58                         }
     58                        },
    5959                    );
    6060
     
    7070                        tb_show( 'Reject with Feedback', '#TB_inline?inlineId=reject-feedback-form' );
    7171                    }
    72                 }
     72                },
    7373            );
    7474
     
    7979             */
    8080            function updateBulkRejectStatus( thisObj ) {
    81                 var form = thisObj.closest( 'form' );
    82                 var commentText = form.find( 'textarea[name="modal_feedback_comment"]' ).val();
    83                 var numberOfCheckedReasons = form.find( 'input[name="modal_feedback_reason"]:checked' ).length;
     81                const form = thisObj.closest( 'form' );
     82                const commentText = form.find( 'textarea[name="modal_feedback_comment"]' ).val();
     83                const numberOfCheckedReasons = form.find( 'input[name="modal_feedback_reason"]:checked' ).length;
    8484                if ( commentText || numberOfCheckedReasons ) {
    8585                    $( 'form#bulk-actions-toolbar-top  option[value="reject"]' ).attr( 'value', 'changesrequested' ).text( 'Changes requested' );
     
    9191                '#modal-reject-btn, #modal-requestchanges-btn',
    9292                function( e ) {
    93                     var comment = '';
    94                     var commentReason = [];
    95                     var commentData = {};
    96                     var form = $( this ).closest( 'form' );
     93                    let comment = '';
     94                    const commentReason = [];
     95                    const commentData = {};
     96                    const form = $( this ).closest( 'form' );
    9797
    9898                    form.find( 'input[name="modal_feedback_reason"]:checked' ).each(
    9999                        function() {
    100100                            commentReason.push( this.value );
    101                         }
     101                        },
    102102                    );
    103103
     
    118118                    commentWithFeedback( commentData, false, 'rejected' );
    119119                    e.preventDefault();
    120                 }
     120                },
    121121            );
    122122
     
    125125                function( e ) {
    126126                    toggleButtons( $( this ), e );
    127                 }
     127                },
    128128            );
    129129            $( '.feedback-comment' ).on(
     
    131131                function( e ) {
    132132                    toggleButtons( $( this ), e );
    133                 }
     133                },
    134134            );
    135135
     
    145145             */
    146146            function toggleButtons( thisObj, event ) {
    147                 var form = thisObj.closest( 'form' );
    148                 var commentText = form.find( 'textarea[name="feedback_comment"]' ).val();
    149                 var div = thisObj.closest( '.meta' );
    150                 var rejectButton = $( '.reject', div );
    151                 var changesRequestedtButton = $( '.changesrequested', div );
    152                 var numberOfCheckedReasons = form.find( 'input[name="feedback_reason"]:checked' ).length;
     147                const form = thisObj.closest( 'form' );
     148                const commentText = form.find( 'textarea[name="feedback_comment"]' ).val();
     149                const div = thisObj.closest( '.meta' );
     150                const rejectButton = $( '.reject', div );
     151                const changesRequestedtButton = $( '.changesrequested', div );
     152                const numberOfCheckedReasons = form.find( 'input[name="feedback_reason"]:checked' ).length;
    153153
    154154                if ( commentText.trim() !== '' || numberOfCheckedReasons ) {
     
    166166                function( e ) {
    167167                    toggleModalButtons( $( this ), e );
    168                 }
     168                },
    169169            );
    170170            $( 'textarea[name="modal_feedback_comment"]' ).on(
     
    172172                function( e ) {
    173173                    toggleModalButtons( $( this ), e );
    174                 }
     174                },
    175175            );
    176176
     
    186186             */
    187187            function toggleModalButtons( thisObj, event ) {
    188                 var form = thisObj.closest( 'form' );
    189                 var commentText = form.find( 'textarea[name="modal_feedback_comment"]' ).val();
    190                 var div = thisObj.closest( '#TB_ajaxContent' );
    191                 var rejectButton = $( '#modal-reject-btn', div );
    192                 var changesRequestedtButton = $( '#modal-requestchanges-btn', div );
    193                 var numberOfCheckedReasons = form.find( 'input[name="modal_feedback_reason"]:checked' ).length;
     188                const form = thisObj.closest( 'form' );
     189                const commentText = form.find( 'textarea[name="modal_feedback_comment"]' ).val();
     190                const div = thisObj.closest( '#TB_ajaxContent' );
     191                const rejectButton = $( '#modal-reject-btn', div );
     192                const changesRequestedtButton = $( '#modal-requestchanges-btn', div );
     193                const numberOfCheckedReasons = form.find( 'input[name="modal_feedback_reason"]:checked' ).length;
    194194
    195195                if ( commentText.trim() !== '' || numberOfCheckedReasons ) {
     
    206206                {
    207207                    tooltipClass: 'hoverTooltip',
    208                 }
     208                },
    209209            );
    210210
    211211            $( 'input[name="feedback_reason"][value="glossary"]' ).change(
    212212                function() {
    213                     var glossaryWords = $( this ).closest( 'tr' ).find( '.original .glossary-word' ).get().map( function( word ) {
     213                    const glossaryWords = $( this ).closest( 'tr' ).find( '.original .glossary-word' ).get().map( function( word ) {
    214214                        return word.innerText;
    215215                    } );
    216216                    if ( $( this ).is( ':checked' ) && glossaryWords.length ) {
    217217                        // eslint-disable-next-line vars-on-top
    218                         var glossaryList = document.createElement( 'ul' );
     218                        const glossaryList = document.createElement( 'ul' );
    219219                        glossaryList.innerHTML = '<h6>Glossary Words</h6>';
    220220                        $( glossaryList ).attr( 'id', 'glossary-item-list' );
    221221                        glossaryWords.forEach(
    222222                            function( item ) {
    223                                 var li = document.createElement( 'li' );
    224                                 var checkbox = $( '<input />', { type: 'checkbox', class: 'glossary-word-item', value: item } );
     223                                const li = document.createElement( 'li' );
     224                                const checkbox = $( '<input />', { type: 'checkbox', class: 'glossary-word-item', value: item } );
    225225                                $( '<label></label>' ).html( checkbox ).append( item ).appendTo( li );
    226226                                glossaryList.appendChild( li );
    227                             }
     227                            },
    228228                        );
    229229                        $( this ).closest( 'ul' ).after( glossaryList );
     
    232232                        $( this ).closest( '.feedback-reason-list' ).siblings( '.feedback-comment' ).find( 'textarea' ).val( '' );
    233233                    }
    234                 }
     234                },
    235235            );
    236236
     
    238238                'change',
    239239                'input.glossary-word-item', function( ) {
    240                     var textArea = $( this ).closest( 'ul' ).next().find( 'textarea' );
     240                    const textArea = $( this ).closest( 'ul' ).next().find( 'textarea' );
    241241                    if ( $( this ).closest( 'ul' ).find( 'input:checked' ).length === 0 ) {
    242242                        textArea.val( '' );
     
    244244                    }
    245245                    // eslint-disable-next-line vars-on-top
    246                     var message = 'There is a problem with ' + ( $( this ).closest( 'ul' ).find( 'input:checked' ).length === 1 ? 'the glossary term' : 'the following glossary terms' ) + ': ' + $( this ).closest( 'ul' ).find( 'input:checked' ).get().map( function( word ) {
     246                    const message = 'There is a problem with ' + ( $( this ).closest( 'ul' ).find( 'input:checked' ).length === 1 ? 'the glossary term' : 'the following glossary terms' ) + ': ' + $( this ).closest( 'ul' ).find( 'input:checked' ).get().map( function( word ) {
    247247                        return word.defaultValue;
    248248                    } ).join( ', ' );
     
    250250                    textArea.val( message );
    251251                } );
    252         }
     252        },
    253253    );
    254254
     
    270270
    271271    function setStatus( that, status ) {
    272         var button = $( that );
    273         var feedbackData = {};
    274         var commentReason = [];
    275         var comment = '';
    276         var div = button.closest( 'div.meta' );
     272        const button = $( that );
     273        const feedbackData = {};
     274        const commentReason = [];
     275        let comment = '';
     276        const div = button.closest( 'div.meta' );
    277277
    278278        div.find( 'input[name="feedback_reason"]:checked' ).each(
    279279            function() {
    280280                commentReason.push( this.value );
    281             }
     281            },
    282282        );
    283283
     
    300300
    301301    function commentWithFeedback( feedbackData, button, status ) {
    302         var data = {};
    303         var div = {};
     302        let data = {};
     303        let div = {};
    304304        if ( button ) {
    305305            div = button.closest( 'div.meta' );
     
    318318
    319319                url: $gp_comment_feedback_settings.url,
    320                 data: data,
    321             }
     320                data,
     321            },
    322322        ).done(
    323323            function() {
     
    329329                    div.find( 'textarea[name="feedback_comment"]' ).val( '' );
    330330                }
    331             }
     331            },
    332332        ).fail(
    333333            function( xhr, msg ) {
     
    340340                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.';
    341341                $gp.notices.error( msg );
    342             }
     342            },
    343343        );
    344344    }
    345345
    346346    function getReasonList( ) {
    347         var commentReasons = $gp_comment_feedback_settings.comment_reasons;
    348         var commentList = '';
    349         var prefix = '';
    350         var suffix = '';
    351         var inputName = '';
     347        const commentReasons = $gp_comment_feedback_settings.comment_reasons;
     348        let commentList = '';
     349        let prefix = '';
     350        let suffix = '';
     351        let inputName = '';
    352352
    353353        // eslint-disable-next-line vars-on-top
    354         for ( var reason in commentReasons ) {
     354        for ( const reason in commentReasons ) {
    355355            prefix = '<div class="modal-item"><label>';
    356356            suffix = '<span class="tooltip dashicons dashicons-info" title="' + commentReasons[ reason ].explanation + '"></span></label></div>';
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/js/translation-helpers.js

    r11992 r12656  
    33    function( $ ) {
    44        return {
    5             init: function( table, fetchNow ) {
     5            init( table, fetchNow ) {
    66                $gp.translation_helpers.table = table;
    77                $gp.translation_helpers.install_hooks();
     
    1010                }
    1111            },
    12             install_hooks: function() {
     12            install_hooks() {
    1313                $( $gp.translation_helpers.table )
    1414                    .on( 'beforeShow', '.editor', $gp.translation_helpers.hooks.initial_fetch )
     
    1717                    .on( 'click', 'a.opt-out-discussion,a.opt-in-discussion', $gp.translation_helpers.hooks.optin_optout_discussion );
    1818            },
    19             initial_fetch: function( $element ) {
    20                 var $helpers = $element.find( '.translation-helpers' );
     19            initial_fetch( $element ) {
     20                const $helpers = $element.find( '.translation-helpers' );
    2121
    2222                if ( $helpers.hasClass( 'loaded' ) || $helpers.hasClass( 'loading' ) ) {
     
    2626                $gp.translation_helpers.fetch( false, $element );
    2727            },
    28             fetch: function( which, $element ) {
    29                 var $helpers;
     28            fetch( which, $element ) {
     29                let $helpers;
    3030                if ( $element ) {
    3131                    $helpers = $element.find( '.translation-helpers' );
     
    3434                }
    3535
    36                 var originalId = $helpers.parent().attr( 'row' ); // eslint-disable-line vars-on-top
    37                 var replytocom = $helpers.parent().attr( 'replytocom' ); // eslint-disable-line vars-on-top
     36                const originalId = $helpers.parent().attr( 'row' ); // eslint-disable-line vars-on-top
     37                const replytocom = $helpers.parent().attr( 'replytocom' ); // eslint-disable-line vars-on-top
    3838                var requestUrl = $gp_translation_helpers_settings.th_url + originalId + '?nohc'; // eslint-disable-line
    3939
     
    6161                        } );
    6262                        $( '.helper-translation-discussion' ).find( 'form.comment-form' ).removeAttr( 'novalidate' );
    63                     }
     63                    },
    6464                );
    6565            },
    66             tab_select: function( $tab ) {
    67                 var tabId = $tab.attr( 'data-tab' );
     66            tab_select( $tab ) {
     67                const tabId = $tab.attr( 'data-tab' );
    6868
    6969                $tab.siblings().removeClass( 'current' );
     
    7373                $( '#' + tabId ).addClass( 'current' );
    7474            },
    75             reply_comment_form: function( $comment ) {
    76                 var commentId = $comment.attr( 'data-commentid' );
     75            reply_comment_form( $comment ) {
     76                const commentId = $comment.attr( 'data-commentid' );
    7777                $( '#comment-reply-' + commentId ).toggle().find( 'textarea' ).focus();
    7878                if ( 'Reply' === $comment.text() ) {
     
    8282                }
    8383            },
    84             optin_optout_discussion: function( $link ) {
    85                 var data = {
     84            optin_optout_discussion( $link ) {
     85                const data = {
    8686                    action: 'optout_discussion_notifications',
    8787                    data: {
     
    9595                        type: 'POST',
    9696                        url: $gp_translation_helpers_settings.ajax_url,
    97                         data: data,
    98                     }
     97                        data,
     98                    },
    9999                ).done(
    100100                    function() {
    101101                        $gp.translation_helpers.fetch( 'discussion' );
    102                     }
     102                    },
    103103                );
    104104            },
    105105            hooks: {
    106                 initial_fetch: function() {
     106                initial_fetch() {
    107107                    $gp.translation_helpers.initial_fetch( $( this ) );
    108108                    return false;
    109109                },
    110                 tab_select: function() {
     110                tab_select() {
    111111                    $gp.translation_helpers.tab_select( $( this ) );
    112112                    return false;
    113113                },
    114                 reply_comment_form: function( event ) {
     114                reply_comment_form( event ) {
    115115                    event.preventDefault();
    116116                    $gp.translation_helpers.reply_comment_form( $( this ) );
    117117                    return false;
    118118                },
    119                 optin_optout_discussion: function( event ) {
     119                optin_optout_discussion( event ) {
    120120                    event.preventDefault();
    121121                    $gp.translation_helpers.optin_optout_discussion( $( this ) );
     
    128128
    129129jQuery( function( $ ) {
    130     var _oldShow = $.fn.show;
     130    const _oldShow = $.fn.show;
    131131    $gp.translation_helpers.init( $( '.translations' ), true );
    132132    if ( typeof window.newShowFunctionAttached === 'undefined' ) {
     
    134134        $.fn.show = function( speed, oldCallback ) {
    135135            return $( this ).each( function() {
    136                 var obj = $( this ),
     136                const obj = $( this ),
    137137                    newCallback = function() {
    138138                        if ( $.isFunction( oldCallback ) ) {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/templates/translation-row-editor-meta-feedback.php

    r12624 r12656  
    55if ( 'waiting' === $translation->translation_status || 'fuzzy' === $translation->translation_status ) :
    66    ?>
    7 <div>
    8     <div class="openai-review">
    9         <p class="suggestions__loading-indicator">ChatGPT review in progress <span aria-hidden="true" class="suggestions__loading-indicator__icon"><span></span><span></span><span></span></span></p>
    10         <div class="auto-review-result"></div>
     7<details open>
     8    <summary class="chatgpt-summary"><?php esc_html_e( 'ChatGPT Review', 'glotpress' ); ?></summary>
     9    <div>
     10        <div class="openai-review">
     11            <p class="suggestions__loading-indicator">ChatGPT review in progress <span aria-hidden="true" class="suggestions__loading-indicator__icon"><span></span><span></span><span></span></span></p>
     12            <div class="auto-review-result"></div>
     13        </div>
    1114    </div>
    12 </div>
     15</details>
    1316<?php endif; ?>
    1417<details open>
Note: See TracChangeset for help on using the changeset viewer.