Making WordPress.org

Changeset 12405


Ignore:
Timestamp:
02/20/2023 02:50:11 PM (2 years ago)
Author:
amieiro
Message:

Translate: Sync gp-translation-helpers with GitHub

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

Legend:

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

    r12205 r12405  
    298298}
    299299ul#glossary-item-list {
    300     list-style-type: none;
     300    list-style-type: none;
    301301    border: #bcc3c3 thin solid;
    302     padding: 10px;
    303     border-radius: 3px;
    304     background: #f2f2f2;
     302    padding: 10px;
     303    border-radius: 3px;
     304    background: #f2f2f2;
    305305}
    306306ul#glossary-item-list h6 {
    307307    margin-top: 3px;
    308     margin-bottom: 8px
     308    margin-bottom: 8px
    309309}
    310310ul#glossary-item-list li label {
    311     margin-left: 5px;
     311    margin-left: 5px;
    312312}
    313313#glossary-item-list li label input[type="checkbox"].glossary-word-item {
    314     margin-right: 5px;
    315 }
     314    margin-right: 5px;
     315}
     316td.gtes-involved a{
     317    text-decoration: none;
     318}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/gp-translation-helpers.php

    r12074 r12405  
    3131
    3232require_once __DIR__ . '/includes/class-gp-route-translation-helpers.php';
     33require_once __DIR__ . '/includes/class-gp-sidebar.php';
    3334require_once __DIR__ . '/includes/class-gp-translation-helpers.php';
    3435require_once __DIR__ . '/includes/class-gth-temporary-post.php';
     
    3637require_once __DIR__ . '/includes/class-wporg-notifications.php';
    3738require_once __DIR__ . '/includes/class-wporg-customizations.php';
     39require_once __DIR__ . '/includes/class-gp-custom-locale-reasons.php';
    3840
    39 add_action( 'gp_init', array( 'GP_Translation_Helpers', 'init' ) );
     41add_action( 'gp_init', array( 'GP_Translation_Helpers', 'init' ) ); // todo: remove this when this plugin will be merged in the GlotPress core.
     42add_action( 'gp_init', array( 'GP_Sidebar', 'init' ) );    // todo: remove this when this plugin will be merged in the GlotPress core.
    4043add_action( 'gp_init', array( 'WPorg_GlotPress_Notifications', 'init' ) );    // todo: include this class in a different plugin.
    4144add_action( 'gp_init', array( 'WPorg_GlotPress_Customizations', 'init' ) );    // todo: include this class in a different plugin.
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/helpers/helper-translation-discussion.php

    r12274 r12405  
    805805     * @return array
    806806     */
    807     public static function get_comment_reasons(): array {
    808         return array(
     807    public static function get_comment_reasons( $locale = null ): array {
     808        $default_reasons = array(
    809809            'style'       => array(
    810810                'name'        => __( 'Style Guide' ),
     
    825825            'punctuation' => array(
    826826                'name'        => __( 'Punctuation' ),
    827                 'explanation' =>
    828                     __( 'The translation is not using the punctuation marks correctly.' ),
     827                'explanation' => __( 'The translation is not using the punctuation marks correctly.' ),
    829828            ),
    830829            'typo'        => array(
     
    833832            ),
    834833        );
     834        $reasons         = apply_filters( 'gp_custom_reasons', $default_reasons, $locale );
     835        return $reasons;
    835836    }
    836837}
     
    898899    $is_linking_comment = preg_match( '!^' . home_url( gp_url() ) . '[a-z0-9_/#-]+$!i', $comment->comment_content );
    899900
    900     $comment_locale = get_comment_meta( $comment->comment_ID, 'locale', true );
    901     $current_locale = $args['locale_slug'];
    902 
     901    $comment_locale         = get_comment_meta( $comment->comment_ID, 'locale', true );
     902    $current_locale         = $args['locale_slug'];
    903903    $current_translation_id = $args['translation_id'];
    904904    $comment_translation_id = get_comment_meta( $comment->comment_ID, 'translation_id', true );
     
    960960            if ( $comment_reason ) :
    961961                ?>
    962                 The translation <?php gth_print_translation( $comment_translation_id, $args ); ?> <a href="<?php echo esc_url( $linked_comment ); ?>"><?php esc_html_e( 'is being discussed here' ); ?></a>.
     962                <p>The translation <?php gth_print_translation( $comment_translation_id, $args ); ?> <a href="<?php echo esc_url( $linked_comment ); ?>"><?php esc_html_e( 'is being discussed here' ); ?></a>.</p>
    963963            <?php else : ?>
    964964                <a href="<?php echo esc_url( $linked_comment ); ?>"><?php esc_html_e( 'Please continue the discussion here' ); ?></a>
     
    10371037            }
    10381038
     1039            if ( $comment_translation_id && $comment_translation_id !== $current_translation_id ) {
     1040                $translation_status = '';
     1041                if ( $_translation_status ) {
     1042
     1043                    $translation_status = ( is_array( $_translation_status ) && array_key_exists( $comment_translation_id, $_translation_status ) ) ? '(' . $_translation_status[ $comment_translation_id ] . ')' : ' (' . $_translation_status[0] . ')';
     1044                }
     1045                gth_print_translation( $comment_translation_id, $args, 'Translation' . $translation_status . ': ' );
     1046            }
    10391047            if ( ! $is_linking_comment ) :
    1040                 if ( $comment_translation_id && $comment_translation_id !== $current_translation_id ) {
    1041                     $translation_status = '';
    1042                     if ( $_translation_status ) {
    1043                         $translation_status = ' (' . $_translation_status . ')';
    1044                     }
    1045                     gth_print_translation( $comment_translation_id, $args, 'Translation' . $translation_status . ': ' );
    1046                 }
    10471048
    10481049                ?>
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/includes/class-gp-translation-helpers.php

    r12205 r12405  
    7575        );
    7676        gp_enqueue_style( 'gp-discussion-css' );
     77
     78        wp_register_style(  // todo: these CSS should be integrated in GlotPress.
     79            'gp-translation-helpers-editor',
     80            plugins_url( 'css/editor.css', __DIR__ ),
     81            array(),
     82            filemtime( plugin_dir_path( __DIR__ ) . 'css/editor.css' )
     83        );
     84        gp_enqueue_style( 'gp-translation-helpers-editor' );
    7785
    7886        add_filter( 'gp_translation_row_template_more_links', array( $this, 'translation_row_template_more_links' ), 10, 5 );
     
    371379     *
    372380     *  @param string $template Template of the current page.
    373      *  @param string $translation_set Current translation set
     381     *  @param array  $translation_set Current translation set.
    374382     *
    375383     * @return void
     
    396404                'nonce'           => wp_create_nonce( 'gp_comment_feedback' ),
    397405                'locale_slug'     => $translation_set['locale_slug'],
    398                 'comment_reasons' => Helper_Translation_Discussion::get_comment_reasons(),
     406                'comment_reasons' => Helper_Translation_Discussion::get_comment_reasons( $translation_set['locale_slug'] ),
     407            )
     408        );
     409
     410        wp_register_script(
     411            'gp-translation-helpers-editor',
     412            plugins_url( 'js/editor.js', __DIR__ ),
     413            array( 'gp-editor' ),
     414            filemtime( plugin_dir_path( __DIR__ ) . 'js/editor.js' ),
     415            true
     416        );
     417        gp_enqueue_scripts( array( 'gp-translation-helpers-editor' ) );
     418
     419        wp_localize_script(
     420            'gp-translation-helpers-editor',
     421            '$gp_translation_helpers_editor',
     422            array(
     423                'translation_helper_url' => gp_url_project( $translation_set['project']->path, gp_url_join( $translation_set['locale_slug'], $translation_set['translation_set']->slug, '-get-translation-helpers' ) ),
     424                'reply_text'             => esc_attr__( 'Reply' ),
     425                'cancel_reply_text'      => esc_html__( 'Cancel reply' ),
     426            )
     427        );
     428        wp_localize_script(
     429            'gp-translation-helpers-editor',
     430            'wpApiSettings',
     431            array(
     432                'root'           => esc_url_raw( rest_url() ),
     433                'nonce'          => wp_create_nonce( 'wp_rest' ),
     434                'admin_ajax_url' => admin_url( 'admin-ajax.php' ),
    399435            )
    400436        );
     
    413449        $helper_discussion    = new Helper_Translation_Discussion();
    414450        $locale_slug          = $helper_discussion->sanitize_comment_locale( sanitize_text_field( $_POST['data']['locale_slug'] ) );
    415         $translation_status   = $helper_discussion->sanitize_translation_status( sanitize_text_field( $_POST['data']['translation_status'] ) );
     451        $translation_status   = ! empty( $_POST['data']['translation_status'] ) ? array_map( array( $helper_discussion, 'sanitize_translation_status' ), $_POST['data']['translation_status'] ) : null;
    416452        $translation_id_array = ! empty( $_POST['data']['translation_id'] ) ? array_map( array( $helper_discussion, 'sanitize_translation_id' ), $_POST['data']['translation_id'] ) : null;
    417453        $original_id_array    = ! empty( $_POST['data']['original_id'] ) ? array_map( array( $helper_discussion, 'sanitize_original_id' ), $_POST['data']['original_id'] ) : null;
     
    451487            foreach ( $original_id_array as $index => $single_original_id ) {
    452488                $comment_id = $this->insert_comment( $comment, $single_original_id, $comment_reason, $translation_id_array[ $index ], $locale_slug, $_SERVER, $translation_status );
    453                 $comment    = get_comment( $comment_id );
    454                 GP_Notifications::add_related_comment( $comment );
     489                $_comment   = get_comment( $comment_id );
     490                GP_Notifications::add_related_comment( $_comment );
    455491            }
    456492        }
     
    461497        }
    462498
    463         wp_send_json_success();
     499        wp_send_json_success( 'success' );
    464500    }
    465501
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/includes/class-wporg-customizations.php

    r12274 r12405  
    4545            );
    4646
     47            add_filter(
     48                'gp_custom_reasons',
     49                function ( $default_reasons, $locale ) {
     50                    return array_merge( $default_reasons, GP_Custom_Locale_Reasons::get_custom_reasons( $locale ) );
     51                },
     52                10,
     53                2
     54            );
     55
    4756            add_filter( 'jetpack_mentions_should_load_ui', '__return_true' );
    4857            add_filter(
     
    5463            );
    5564
     65            add_filter(
     66                'gp_validators_involved',
     67                function ( $gtes_involved, $locale_slug, $original_id, $comment_authors ) {
     68                    $gte_emails   = WPorg_GlotPress_Notifications::get_gte_email_addresses( $locale_slug );
     69                    $pte_emails   = WPorg_GlotPress_Notifications::get_pte_email_addresses_by_project_and_locale( $original_id, $locale_slug );
     70                    $clpte_emails = WPorg_GlotPress_Notifications::get_clpte_email_addresses_by_project( $original_id );
     71                    return array_intersect( array_merge( $gte_emails, $pte_emails, $clpte_emails ), $comment_authors );
     72
     73                },
     74                10,
     75                4
     76            );
     77
     78            add_filter(
     79                'gp_involved_table_heading',
     80                function () {
     81                    return __( 'GTEs/PTEs/CLPTEs Involved' );
     82                }
     83            );
    5684        }
    5785    }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/js/reject-feedback.js

    r12274 r12405  
    66            var translationIds = [];
    77            var originalIds = [];
     8            var bulkTranslationStatus = [];
     9            var translationStatuses = {};
     10            var statusIndex = 0;
    811            var modalFeedbackForm =
    912            '<div id="reject-feedback-form" style="display:none;">' +
     
    3033                        function() {
    3134                            var selectedRow = $( this ).parents( 'tr.preview' );
     35                            var translationStatus = '';
     36
    3237                            if ( ! selectedRow.hasClass( 'untranslated' ) ) {
     38                                translationStatus = selectedRow.attr( 'class' ).split( ' ' )[ 1 ].substring( 7 );
     39                                bulkTranslationStatus.push( translationStatus );
    3340                                return selectedRow.attr( 'row' );
    3441                            }
     
    4653                                originalIds.push( originalId );
    4754                                translationIds.push( translationId );
     55                                translationStatuses[ translationId ] = bulkTranslationStatus[ statusIndex ];
    4856                            }
     57                            statusIndex++;
    4958                        }
    5059                    );
     
    105114                    commentData.translation_id = translationIds;
    106115                    commentData.is_bulk_reject = true;
     116                    commentData.translation_status = translationStatuses;
     117
    107118                    commentWithFeedback( commentData, false, 'rejected' );
    108119                    e.preventDefault();
     
    283294        feedbackData.original_id = [ $gp.editor.current.original_id ];
    284295        feedbackData.translation_id = [ $gp.editor.current.translation_id ];
    285         feedbackData.translation_status = status;
     296        feedbackData.translation_status = [ status ];
    286297
    287298        commentWithFeedback( feedbackData, button, status );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/templates/discussions-dashboard.php

    r12275 r12405  
    104104        <th>Author</th>
    105105        <th>Submitted on</th>
     106        <th><?php echo esc_html( apply_filters( 'gp_involved_table_heading', __( 'Validators Involved' ) ) ); ?></th>
    106107    </tr>
    107108    </thead>
     
    119120            $project_name   = ( $parent_project ) ? $parent_project->name : $project->name;
    120121            $project_link   = gp_link_project_get( $project, esc_html( $project_name ) );
     122
     123            $comment_authors            = array_unique( array_column( $post_comments, 'comment_author_email' ) );
     124            $validator_emails           = GP_Notifications::get_validators_email_addresses( $project->path );
     125            $validators_involved_emails = array_intersect( $validator_emails, $comment_authors );
     126
     127            $validators_involved_emails = apply_filters( 'gp_validators_involved', $validators_involved_emails, $locale_slug, $original_id, $comment_authors );
     128
     129            $validator_involved_names = array_map(
     130                function( $validator ) {
     131                    $validator_user = get_user_by( 'email', $validator );
     132                    return '<a href="' . esc_url( gp_url_profile( $validator_user->user_nicename ) ) . '">' . esc_html( $validator_user->display_name ) . '</a>';
     133                },
     134                $validators_involved_emails
     135            );
    121136
    122137            $first_comment        = reset( $post_comments );
     
    201216                <td><?php echo get_comment_author_link( $first_comment ); ?></td>
    202217                <td><?php echo esc_html( $first_comment->comment_date ); ?></td>
     218                <td class="gtes-involved">
     219                    <?php
     220                        echo wp_kses(
     221                            implode( ', ', $validator_involved_names ),
     222                            array(
     223                                'a' => array(
     224                                    'href'  => array(),
     225                                    'class' => array(),
     226                                ),
     227                            )
     228                        );
     229                    ?>
     230            </td>
    203231            </tr>
    204232            <?php
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/templates/translation-row-editor-meta-feedback.php

    r12205 r12405  
    99            <ul class="feedback-reason-list">
    1010            <?php
    11                 $comment_reasons = Helper_Translation_Discussion::get_comment_reasons();
     11                $comment_reasons = Helper_Translation_Discussion::get_comment_reasons( $locale_slug );
    1212            foreach ( $comment_reasons as $key => $reason ) :
    1313                ?>
     
    1818            </ul>
    1919            <div class="feedback-comment">
    20                 <label><?php esc_html_e( 'Comment (Optional)', 'glotpress' ); ?>
    21                     <textarea name="feedback_comment"></textarea>
     20                <label for="feedback_comment"><?php esc_html_e( 'Comment (Optional)', 'glotpress' ); ?>
    2221                </label>
     22                <textarea name="feedback_comment"></textarea>
     23
    2324                <label class="note">Please note that all feedback is visible to the public.</label>
    2425            </div>
Note: See TracChangeset for help on using the changeset viewer.