Making WordPress.org


Ignore:
Timestamp:
01/14/2021 03:22:06 AM (4 years ago)
Author:
dd32
Message:

Translate: When a translator re-submits a translation suggestion, automatically reject their previous submitted translations for that original.

This will mean that those who see a Translation warning, fix it, and then re-submit will only have 1 waiting translation rather than 2.

Fixes #5576.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/class-plugin.php

    r10575 r10576  
    5151        add_filter( 'wporg_translate_language_pack_theme_args', array( $this, 'set_version_for_default_themes_in_development' ), 10, 2 );
    5252
    53         add_filter( 'gp_translation_prepare_for_save', array( $this, 'auto_reject_already_rejected' ), 100, 2 );
     53        add_filter( 'gp_translation_prepare_for_save', array( $this, 'auto_reject_already_rejected' ), 10, 2 );
     54        add_action( 'gp_translation_created', array( $this, 'auto_reject_replaced_suggestions' ) );
    5455
    5556        // Cron.
     
    257258
    258259    /**
     260     * Auto-Rejects a translators submissions when the translator submits a replacement suggestion.
     261     *
     262     * @see https://github.com/GlotPress/GlotPress-WP/issues/889
     263     *
     264     * @param GP_Translation $translation Translation instance.
     265     */
     266    public function auto_reject_replaced_suggestions( GP_Translation $translation ) {
     267        // If the suggestion isn't in a waiting status, it's can be skipped, they've got better access than most.
     268        if ( 'waiting' !== $translation->status ) {
     269            return;
     270        }
     271
     272        $translation_set = GP::$translation_set->get( $translation->translation_set_id );
     273        $project = GP::$project->get( $translation_set->project_id );
     274
     275        // If the current user can approve / write to the project, skip. Probably not needed due to the `waiting` check above.
     276        if (
     277            GP::$permission->current_user_can( 'approve', 'translation-set', $translation_set->id )
     278            ||
     279            GP::$permission->current_user_can( 'write', 'project', $project->id )
     280        ) {
     281            return;
     282        }
     283
     284        $previous_translations = GP::$translation->for_translation(
     285            $project,
     286            $translation_set,
     287            'no-limit',
     288            array(
     289                'user_login'  => get_user_by( 'ID', $translation->user_id )->user_login,
     290                'original_id' => $translation->original_id,
     291                'status'      => 'waiting_or_fuzzy',
     292            ),
     293            array()
     294        );
     295
     296        // This will include the current translation, so skip that.
     297        foreach ( $previous_translations as $prev_translation ) {
     298            if ( $prev_translation->id >= $translation->id ) {
     299                // >= to match the current translation and any race-condition situations
     300                continue;
     301            }
     302
     303            // Previous translation from this translator, reject it.
     304            GP::$translation->get( $prev_translation->id )->reject();
     305        }
     306    }
     307
     308    /**
    259309     * Adds a link to view originals in consistency tool.
    260310     *
Note: See TracChangeset for help on using the changeset viewer.