Making WordPress.org


Ignore:
Timestamp:
02/18/2018 05:24:48 PM (7 years ago)
Author:
ocean90
Message:

Translate: Include all types of translation editors in the editors list of a project.

Fixes #3461.

File:
1 edited

Legend:

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

    r6005 r6691  
    358358
    359359    /**
    360      * Retrieves contributors of a project.
     360     * Retrieves translation editors of a project.
     361     *
     362     * Also includes cross-locale editors and editors of parent projects.
    361363     *
    362364     * @param GP_Project $project     A GlotPress project.
    363365     * @param string     $locale_slug Slug of the locale.
    364      * @param string     $set_slug    Slug of the translation set.
    365      * @return array Contributors.
    366      */
    367     private function get_locale_contributors( $project, $locale_slug, $set_slug ) {
     366     * @return array List of user IDs.
     367     */
     368    private function get_translation_editors( $project, $locale_slug ) {
    368369        global $wpdb;
    369370
    370         $locale_contributors = array(
    371             'editors'      => array(),
    372             'contributors' => array(),
    373         );
    374 
    375371        // Get the translation editors of the project.
    376         $editors = $wpdb->get_col( $wpdb->prepare( "
     372        $editors = (array) $wpdb->get_col( $wpdb->prepare( "
    377373            SELECT
    378374                `user_id`
     
    380376            WHERE
    381377                `project_id` = %d
    382                 AND `locale` = %s
     378                AND `locale` IN (%s, 'all-locales')
    383379        ", $project->id, $locale_slug ) );
     380
     381        if ( $project->parent_project_id ) {
     382            $parent_project_id = $project->parent_project_id;
     383            $parent_project = GP::$project->get( $parent_project_id );
     384            while ( $parent_project_id ) {
     385                $editors = $editors + (array) $wpdb->get_col( $wpdb->prepare( "
     386                    SELECT
     387                        `user_id`
     388                    FROM {$wpdb->wporg_translation_editors}
     389                    WHERE
     390                        `project_id` = %d
     391                        AND `locale` IN (%s, 'all-locales')
     392                ", $parent_project->id, $locale_slug ) );
     393
     394                $parent_project = GP::$project->get( $parent_project_id );
     395                $parent_project_id = $parent_project->parent_project_id;
     396            }
     397        }
     398
     399        return $editors;
     400    }
     401
     402    /**
     403     * Retrieves contributors of a project.
     404     *
     405     * @param GP_Project $project     A GlotPress project.
     406     * @param string     $locale_slug Slug of the locale.
     407     * @param string     $set_slug    Slug of the translation set.
     408     * @return array Contributors.
     409     */
     410    private function get_locale_contributors( $project, $locale_slug, $set_slug ) {
     411        global $wpdb;
     412
     413        $locale_contributors = array(
     414            'editors'      => array(),
     415            'contributors' => array(),
     416        );
     417
     418        // Get the translation editors of the project.
     419        $editors = $this->get_translation_editors( $project, $locale_slug );
    384420
    385421        // Get the names of the translation editors.
     
    468504        unset( $contributors, $editors );
    469505
    470         uasort( $locale_contributors['contributors'], array( $this, '_sort_contributors_by_total_count_callback' ) );
     506        uasort( $locale_contributors['contributors'], function( $a, $b ) {
     507            return $a->total_count < $b->total_count;
     508        } );
     509
     510        uasort( $locale_contributors['editors'], function( $a, $b ) {
     511            return strcasecmp( $a->display_name, $b->display_name );
     512        } );
    471513
    472514        return $locale_contributors;
     
    891933    }
    892934
    893     private function _sort_contributors_by_total_count_callback( $a, $b ) {
    894         return $a->total_count < $b->total_count;
    895     }
    896 
    897935    private function _sort_reverse_name_callback( $a, $b ) {
    898936        // The Waiting project should always be first.
     
    903941    }
    904942
    905     private function _sort_name_callback( $a, $b ) {
    906         return strcasecmp( $a->name, $b->name );
    907     }
    908 
    909943    private function _encode( $raw ) {
    910944        $raw = mb_convert_encoding( $raw, 'UTF-8', 'ASCII, JIS, UTF-8, Windows-1252, ISO-8859-1' );
Note: See TracChangeset for help on using the changeset viewer.