Making WordPress.org

Changeset 5344


Ignore:
Timestamp:
04/15/2017 10:14:58 PM (9 years ago)
Author:
ocean90
Message:

WP i18n teams: Add locale managers to detail pages.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wp-i18n-teams
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wp-i18n-teams/css/i18n-teams.css

    r4430 r5344  
    244244article.page .translators-info table tr td:last-child {
    245245        padding-right: 1em;
     246}
     247
     248article.page .translators-info table td:first-of-type {
     249        width: auto;
    246250}
    247251
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wp-i18n-teams/views/locale-details.php

    r5160 r5344  
    1111        <ul id="locale-details">
    1212                <li>
    13                         <strong><?php _e( 'Locale site:', 'wporg' ); ?></strong>
    14                         <?php if ( $locale_data['rosetta_site_url'] ) : ?>
    15                                 <a href="<?php echo esc_url( $locale_data['rosetta_site_url'] ); ?>"><?php echo parse_url( $locale_data['rosetta_site_url'], PHP_URL_HOST ); ?></a>
    16                         <?php else : ?>
    17                                 &mdash;
    18                         <?php endif; ?>
    19                 </li>
    20                 <li>
    21                         <strong><?php _e( 'Team site:', 'wporg' ); ?></strong>
    22                         <?php if ( $locale_data['team_url'] ) : ?>
    23                                 <a href="<?php echo esc_url( $locale_data['team_url'] ); ?>"><?php
    24                                         $url = parse_url( $locale_data['team_url'] );
    25                                         printf( '%s%s', $url['host'], $url['path'] );
    26                                 ?></a>
    27                         <?php else : ?>
    28                                 &mdash;
    29                         <?php endif; ?>
    30                 </li>
    31                 <li>
    32                         <strong><?php _e( 'Forums:', 'wporg' ); ?></strong>
    33                         <?php if ( $locale_data['forums_url'] ) : ?>
    34                                 <a href="<?php echo esc_url( $locale_data['forums_url'] ); ?>"><?php
    35                                         $url = parse_url( $locale_data['forums_url'] );
    36                                         printf( '%s%s', $url['host'], $url['path'] );
    37                                 ?></a>
    38                         <?php else : ?>
     13                        <strong><?php _e( 'Sites:', 'wporg' ); ?></strong>
     14                        <?php
     15                        if ( $locale_data['sites'] ) :
     16                                echo implode( ', ', array_map( function( $site ) {
     17                                        return sprintf(
     18                                                '<a href="%s">%s (%s)</a>',
     19                                                esc_url( $site->home ),
     20                                                esc_html( $site->blogname ),
     21                                                esc_html( $site->domain . $site->path )
     22                                        );
     23                                },  $locale_data['sites'] ) );
     24                        else : ?>
    3925                                &mdash;
    4026                        <?php endif; ?>
     
    8066</div>
    8167
     68<?php if ( ! empty( $locale_data['locale_managers'] ) ) : ?>
     69        <h2><?php printf( __( 'Locale Managers (%s)', 'wporg' ), number_format_i18n( count( $locale_data['locale_managers'] ) ) ); ?></h2>
    8270
    83 <h2><?php printf( __( 'General Translation Editors (%s)', 'wporg' ), number_format_i18n( count( $locale_data['validators'] ) ) ); ?></h2>
     71        <ul class="validators">
     72                <?php foreach ( $locale_data['locale_managers'] as $locale_manager ) :
     73                        ?>
     74                        <li>
     75                                <a class="profile" href="https://profiles.wordpress.org/<?php echo esc_attr( $locale_manager['nice_name'] ); ?>"><?php
     76                                        echo get_avatar( $locale_manager['email'], 60 );
     77                                        echo esc_html( $locale_manager['display_name'] );
     78                                        ?></a>
     79                                <?php
     80                                if ( $locale_manager['slack'] ) {
     81                                        printf( '<span class="user-slack">@%s on <a href="%s">Slack</a></span>', $locale_manager['slack'], 'https://make.wordpress.org/chat/' );
     82                                }
     83                                ?>
     84                        </li>
     85                <?php endforeach; ?>
     86        </ul>
     87<?php endif; ?>
    8488
    85 <?php if ( empty( $locale_data['validators'] ) ) : ?>
    86         <p><?php
    87                 /* translators: %s: language name in English */
    88                 printf( __( '%s does not have General or Project translation editors yet.', 'wporg' ), $locale->english_name );
    89         ?></p>
    90 <?php else : ?>
     89<?php if ( ! empty( $locale_data['validators'] ) ) : ?>
     90        <h2><?php printf( __( 'General Translation Editors (%s)', 'wporg' ), number_format_i18n( count( $locale_data['validators'] ) ) ); ?></h2>
     91
    9192        <ul class="validators">
    9293                <?php foreach ( $locale_data['validators'] as $validator ) :
     
    106107        </ul>
    107108<?php endif; ?>
    108 
    109109
    110110<?php if ( ! empty( $locale_data['project_validators'] ) ) : ?>
     
    129129<?php endif; ?>
    130130
    131 <h2><?php printf( __( 'All Translation Contributors (%s)', 'wporg' ), number_format_i18n( count( $locale_data['translators'] ) ) ); ?></h2>
     131<?php if ( ! empty( $locale_data['translators'] ) ) : ?>
     132        <h2><?php printf( __( 'All Translation Contributors (%s)', 'wporg' ), number_format_i18n( count( $locale_data['translators'] ) ) ); ?></h2>
    132133
    133 <?php if ( empty( $locale_data['translators'] ) ) : ?>
    134         <p><?php printf( __( '%s does not have any translators yet.', 'wporg' ), $locale->english_name ); ?></p>
    135 <?php else :?>
    136134        <p>
    137135                <?php
     
    149147<?php endif; ?>
    150148
    151 <p class="alert alert-info" role="alert">
    152         <a href="https://translate.wordpress.org/locale/<?php echo esc_attr( $locale->slug ); ?>"><?php
     149<?php
     150$notice = sprintf(
     151        '%s <a href="https://translate.wordpress.org/locale/%s">%s</a>',
     152        __( 'Is this a language that you speak?', 'wporg' ),
     153        esc_attr( $locale->slug ),
     154        sprintf(
    153155                /* translators: %s: language name in English */
    154                 printf( __( 'Is this a language that you speak? Join the WordPress translation team for %s!', 'wporg' ), $locale->english_name );
    155         ?></a>
    156 </p>
     156                __( 'Join the WordPress translation team for %s!', 'wporg' ),
     157                esc_html( $locale->english_name )
     158        )
     159);
     160echo do_shortcode( "[info]{$notice}[/info]" );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wp-i18n-teams/wp-i18n-teams.php

    r4441 r5344  
    202202                        $statuses[ $language_pack_status ]++;
    203203
    204                         $forums_url = $team_url = '';
    205                         if ( $subdomain ) {
    206                                 $result = get_sites( array(
    207                                         'domain'   => $subdomain . '.wordpress.org',
    208                                         'path__in' => array( '/support/', '/forums/' ),
    209                                         'number'   => 1,
    210                                 ) );
    211                                 $site = array_shift( $result );
    212                                 if ( $site ) {
    213                                         $forums_url = get_home_url( $site->id, '/' );
    214                                 }
    215 
    216                                 $result = get_sites( array(
    217                                         'domain'   => $subdomain . '.wordpress.org',
    218                                         'path__in' => array( '/team/' ),
    219                                         'number'   => 1,
    220                                 ) );
    221                                 $site = array_shift( $result );
    222                                 if ( $site ) {
    223                                         $team_url = get_home_url( $site->id, '/' );
    224                                 }
    225                         }
     204                        $sites = get_sites( [
     205                                'locale'     => $locale->wp_locale,
     206                                'network_id' => WPORG_GLOBAL_NETWORK_ID,
     207                                'orderby'    => 'path_length',
     208                                'number'     => '',
     209                        ] );
    226210
    227211                        $locale_data[ $locale->wp_locale ] = array(
     
    229213                                'translation_status'   => $translation_status,
    230214                                'language_pack_status' => $language_pack_status,
    231                                 'rosetta_site_url'     => $subdomain ? 'https://' . $subdomain . '.wordpress.org' : false,
    232                                 'forums_url'           => $forums_url ? $forums_url : false,
    233                                 'team_url'             => $team_url ? $team_url : false,
     215                                'sites'                => $sites,
     216                                'subdomain'            => $subdomain,
     217                                'rosetta_site_url'     => "https://$subdomain.wordpress.org/",
    234218                                'latest_release'       => $latest_release ? $latest_release : false,
    235219                        );
     
    272256                $latest_release = $locale_data['latest_release'];
    273257                if ( $latest_release ) {
    274                         $locale_data['localized_core_url'] = sprintf( '%s/wordpress-%s-%s.zip', $locale_data['rosetta_site_url'], $latest_release, $locale->wp_locale );
     258                        $locale_data['localized_core_url'] = sprintf( 'https://%s.wordpress.org/wordpress-%s-%s.zip', $locale_data['subdomain'], $latest_release, $locale->wp_locale );
    275259                        $language_packs_data = $this->get_language_packs_data();
    276260
     
    294278
    295279                $contributors = $this->get_contributors( $locale );
     280                $locale_data['locale_managers'] = $contributors['locale_managers'];
    296281                $locale_data['validators'] = $contributors['validators'];
    297282                $locale_data['project_validators'] = $contributors['project_validators'];
     
    313298                }
    314299
    315                 $contributors = array();
     300                $contributors = [];
     301                $contributors['locale_managers'] = $this->get_locale_managers( $locale );
    316302                $contributors['validators'] = $this->get_general_translation_editors( $locale );
    317303                $contributors['project_validators'] = $this->get_project_translation_editors( $locale );
     
    355341
    356342        /**
    357          * Get the general translation editors for the given locale.
     343         * Get the locale managers for the given locale.
    358344         *
    359345         * @param GP_Locale $locale
    360346         * @return array
    361347         */
    362         private function get_general_translation_editors( $locale ) {
    363                 global $wpdb;
    364 
    365                 $editors = array();
    366 
    367                 $users = $wpdb->get_col( $wpdb->prepare( "
    368                         SELECT `user_id` FROM `translate_translation_editors`
    369                         WHERE `project_id` = '0' AND `locale` = %s
    370                 ", $locale->slug ) );
    371 
    372                 if ( ! $users ) {
    373                         return $editors;
    374                 }
    375 
    376                 $user_data = $wpdb->get_results( "SELECT ID, user_nicename, display_name, user_email FROM $wpdb->users WHERE ID IN (" . implode( ',', $users ) . ")" );
    377                 foreach ( $user_data as $user ) {
    378                         if ( $user->display_name && $user->display_name !== $user->user_nicename ) {
    379                                 $editors[ $user->user_nicename ] = array(
    380                                         'display_name' => $user->display_name,
    381                                         'email'        => $user->user_email,
    382                                         'nice_name'    => $user->user_nicename,
    383                                         'slack'        => self::get_slack_username( $user->ID ),
    384                                 );
    385                         } else {
    386                                 $editors[ $user->user_nicename ] = array(
    387                                         'display_name' => $user->user_nicename,
    388                                         'email'        => $user->user_email,
    389                                         'nice_name'    => $user->user_nicename,
    390                                         'slack'        => self::get_slack_username( $user->ID ),
    391                                 );
    392                         }
    393                 }
    394 
    395                 uasort( $editors, array( $this, '_sort_display_name_callback' ) );
    396 
    397                 return $editors;
     348        private function get_locale_managers( $locale ) {
     349                $locale_managers = [];
     350
     351                $result = get_sites( [
     352                        'locale'     => $locale->wp_locale,
     353                        'network_id' => WPORG_GLOBAL_NETWORK_ID,
     354                        'path'       => '/',
     355                        'fields'     => 'ids',
     356                        'number'     => '1',
     357                ] );
     358                $site_id = array_shift( $result );
     359                if ( ! $site_id ) {
     360                        return $locale_managers;
     361                }
     362
     363                $users = get_users( [
     364                        'blog_id'     => $site_id,
     365                        'role'        => 'locale_manager',
     366                        'count_total' => false,
     367                ] );
     368
     369                foreach ( $users as $user ) {
     370                        $locale_managers[ $user->user_nicename ] = $this->prepare_user( $user );
     371                }
     372
     373                uasort( $locale_managers, [ $this, '_sort_display_name_callback' ] );
     374
     375                return $locale_managers;
    398376        }
    399377
     
    404382         * @return array
    405383         */
     384        private function get_general_translation_editors( $locale ) {
     385                $editors = [];
     386
     387                $result = get_sites( [
     388                        'locale'     => $locale->wp_locale,
     389                        'network_id' => WPORG_GLOBAL_NETWORK_ID,
     390                        'path'       => '/',
     391                        'fields'     => 'ids',
     392                        'number'     => '1',
     393                ] );
     394                $site_id = array_shift( $result );
     395                if ( ! $site_id ) {
     396                        return $editors;
     397                }
     398
     399                $users = get_users( [
     400                        'blog_id'     => $site_id,
     401                        'role'        => 'general_translation_editor',
     402                        'count_total' => false,
     403                ] );
     404
     405                foreach ( $users as $user ) {
     406                        $editors[ $user->user_nicename ] = $this->prepare_user( $user );
     407                }
     408
     409                uasort( $editors, [ $this, '_sort_display_name_callback' ] );
     410
     411                return $editors;
     412        }
     413
     414        /**
     415         * Get the general translation editors for the given locale.
     416         *
     417         * @param GP_Locale $locale
     418         * @return array
     419         */
    406420        private function get_project_translation_editors( $locale ) {
    407                 global $wpdb;
    408 
    409                 $editors = array();
    410 
    411                 $users = $wpdb->get_col( $wpdb->prepare( "
    412                         SELECT `user_id` FROM `translate_translation_editors`
    413                         WHERE `project_id` <> '0' AND `locale` = %s
    414                 ", $locale->slug ) );
    415 
    416                 if ( ! $users ) {
     421                $editors = [];
     422
     423                $result = get_sites( [
     424                        'locale'     => $locale->wp_locale,
     425                        'network_id' => WPORG_GLOBAL_NETWORK_ID,
     426                        'path'       => '/',
     427                        'fields'     => 'ids',
     428                        'number'     => '1',
     429                ] );
     430                $site_id = array_shift( $result );
     431                if ( ! $site_id ) {
    417432                        return $editors;
    418433                }
    419434
    420                 $user_data = $wpdb->get_results( "SELECT ID, user_nicename, display_name, user_email FROM $wpdb->users WHERE ID IN (" . implode( ',', $users ) . ")" );
    421                 foreach ( $user_data as $user ) {
    422                         if ( $user->display_name && $user->display_name !== $user->user_nicename ) {
    423                                 $editors[ $user->user_nicename ] = array(
    424                                         'display_name' => $user->display_name,
    425                                         'email'        => $user->user_email,
    426                                         'nice_name'    => $user->user_nicename,
    427                                         'slack'        => self::get_slack_username( $user->ID ),
    428                                 );
    429                         } else {
    430                                 $editors[ $user->user_nicename ] = array(
    431                                         'display_name' => $user->user_nicename,
    432                                         'email'        => $user->user_email,
    433                                         'nice_name'    => $user->user_nicename,
    434                                         'slack'        => self::get_slack_username( $user->ID ),
    435                                 );
    436                         }
    437                 }
    438 
    439                 uasort( $editors, array( $this, '_sort_display_name_callback' ) );
     435                $users = get_users( [
     436                        'blog_id'     => $site_id,
     437                        'role'        => 'translation_editor',
     438                        'count_total' => false,
     439                ] );
     440
     441                foreach ( $users as $user ) {
     442                        $editors[ $user->user_nicename ] = $this->prepare_user( $user );
     443                }
     444
     445                uasort( $editors, [ $this, '_sort_display_name_callback' ] );
    440446
    441447                return $editors;
     448        }
     449
     450        /**
     451         * Prepares user objects for output.
     452         *
     453         * @param \WP_User $user The user.
     454         * @return array List of user data.
     455         */
     456        private function prepare_user( $user ) {
     457                if ( $user->display_name && $user->display_name !== $user->user_nicename ) {
     458                        return [
     459                                'display_name' => $user->display_name,
     460                                'email'        => $user->user_email,
     461                                'nice_name'    => $user->user_nicename,
     462                                'slack'        => self::get_slack_username( $user->ID ),
     463                        ];
     464                } else {
     465                        return [
     466                                'display_name' => $user->user_nicename,
     467                                'email'        => $user->user_email,
     468                                'nice_name'    => $user->user_nicename,
     469                                'slack'        => self::get_slack_username( $user->ID ),
     470                        ];
     471                }
    442472        }
    443473
Note: See TracChangeset for help on using the changeset viewer.