Making WordPress.org

Changeset 13565


Ignore:
Timestamp:
04/18/2024 10:06:30 AM (15 months ago)
Author:
amieiro
Message:

Translate: Sync "Translation Events" from GitHub

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/stats/stats-calculator.php

    r13541 r13565  
    303303
    304304    /**
    305      * Check if a user is a first time contributor.
     305     * Check if a user is a new translation contributor. A new contributor is a user who has made 10 or fewer translations before event start time.
    306306     *
    307307     * @param Event_Start_Date $event_start The event start date.
    308308     * @param int              $user_id      The user ID.
    309309     *
    310      * @return bool True if the user is a first time contributor, false otherwise.
    311      */
    312     public function is_first_time_contributor( $event_start, $user_id ) {
    313         global $wpdb, $gp_table_prefix;
    314 
     310     * @return bool True if the user is a new translation contributor, false otherwise.
     311     */
     312    public function is_new_translation_contributor( $event_start, $user_id ) {
     313        global $wpdb, $gp_table_prefix;
     314        $new_contributor_max_translation_count = 10;
     315        $event_start_date_time                 = $event_start->__toString();
    315316        // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
    316317        // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery
    317318        // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching
    318319        // phpcs:disable WordPress.DB.DirectDatabaseQuery.SchemaChange
    319         $users_first_translation_date = $wpdb->get_var(
    320             $wpdb->prepare(
    321                 "
    322             select min(date_added) from {$gp_table_prefix}translations where user_id = %d
     320        $user_translations_count = $wpdb->get_var(
     321            $wpdb->prepare(
     322                "
     323            select count(*) from {$gp_table_prefix}translations where user_id = %d and date_added < %s
    323324        ",
    324325                array(
    325326                    $user_id,
    326                 )
    327             )
    328         );
    329 
    330         if ( get_userdata( $user_id ) && ! $users_first_translation_date ) {
     327                    $event_start_date_time,
     328                )
     329            )
     330        );
     331
     332        if ( get_userdata( $user_id ) && ! $user_translations_count ) {
    331333            return true;
    332334        }
    333         $event_start_date_time  = new DateTimeImmutable( $event_start->__toString(), new DateTimeZone( 'UTC' ) );
    334         $first_translation_date = new DateTimeImmutable( $users_first_translation_date, new DateTimeZone( 'UTC' ) );
    335         // A first time contributor is someone whose first translation was made not earlier than 24 hours before the event.
    336         $event_start_date_time = $event_start_date_time->modify( '-1 day' );
    337         return $event_start_date_time <= $first_translation_date;
     335        return $user_translations_count <= $new_contributor_max_translation_count;
    338336    }
    339337}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/templates/event.php

    r13541 r13565  
    66namespace Wporg\TranslationEvents;
    77
     8use GP_Locales;
    89use WP_User;
    910use Wporg\TranslationEvents\Attendee\Attendee;
     
    4445        <?php if ( ! empty( $contributors ) ) : ?>
    4546            <div class="event-contributors">
    46                 <h2><?php esc_html_e( 'Contributors', 'gp-translation-events' ); ?></h2>
     47                <h2>
     48                <?php
     49                // translators: %d is the number of contributors.
     50                echo esc_html( sprintf( __( 'Contributors (%d)', 'gp-translation-events' ), number_format_i18n( count( $contributors ) ) ) );
     51                ?>
     52                </h2>
    4753                <ul>
    4854                    <?php foreach ( $contributors as $contributor ) : ?>
     
    5056                            <a href="<?php echo esc_url( get_author_posts_url( $contributor->ID ) ); ?>" class="avatar"><?php echo get_avatar( $contributor->ID, 48 ); ?></a>
    5157                            <a href="<?php echo esc_url( get_author_posts_url( $contributor->ID ) ); ?>" class="name"><?php echo esc_html( get_the_author_meta( 'display_name', $contributor->ID ) ); ?></a>
    52                             <?php if ( $stats_calculator->is_first_time_contributor( $event_start, $contributor->ID ) ) : ?>
     58                            <?php if ( $stats_calculator->is_new_translation_contributor( $event_start, $contributor->ID ) ) : ?>
    5359                                <span class="first-time-contributor-tada" title="<?php esc_html_e( 'New Translation Contributor', 'gp-translation-events' ); ?>"></span>
    5460                            <?php endif; ?>
     
    7884        <?php if ( ! empty( $attendees ) && ( ! $event->end()->is_in_the_past() || ( ( $attendee instanceof Attendee && $attendee->is_host() ) || current_user_can( 'manage_options' ) || $user->ID === $event->author_id() ) ) ) : ?>
    7985            <div class="event-attendees">
    80                 <h2><?php esc_html_e( 'Attendees', 'gp-translation-events' ); ?></h2>
     86                <h2>
     87                <?php
     88                // translators: %d is the number of attendees.
     89                echo esc_html( sprintf( __( 'Attendees (%d)', 'gp-translation-events' ), number_format_i18n( count( $attendees ) ) ) );
     90                ?>
     91                </h2>
    8192                <ul>
    8293                    <?php foreach ( $attendees as $_user ) : ?>
     
    8495                            <a href="<?php echo esc_url( get_author_posts_url( $_user->ID ) ); ?>" class="avatar"><?php echo get_avatar( $_user->ID, 48 ); ?></a>
    8596                            <a href="<?php echo esc_url( get_author_posts_url( $_user->ID ) ); ?>" class="name"><?php echo esc_html( get_the_author_meta( 'display_name', $_user->ID ) ); ?></a>
    86                             <?php if ( $stats_calculator->is_first_time_contributor( $event_start, $_user->ID ) ) : ?>
     97                            <?php if ( $stats_calculator->is_new_translation_contributor( $event_start, $_user->ID ) ) : ?>
    8798                                <span class="first-time-contributor-tada" title="<?php esc_html_e( 'New Translation Contributor', 'gp-translation-events' ); ?>"></span>
    8899                            <?php endif; ?>
     
    147158                        <?php
    148159                        foreach ( explode( ',', $row->locales ) as $_locale ) {
    149                             $_locale = \GP_Locales::by_slug( $_locale );
     160                            $_locale = GP_Locales::by_slug( $_locale );
    150161                            ?>
    151                             <a href="<?php echo esc_url( gp_url_project_locale( $row->project, $_locale, 'default' ) ); ?>"><?php echo esc_html( $_locale->english_name ); ?></a>
     162                            <a href="<?php echo esc_url( gp_url_project_locale( $row->project, $_locale->slug, 'default' ) ); ?>"><?php echo esc_html( $_locale->english_name ); ?></a>
    152163                            <?php
    153164                        }
     
    200211                                    function ( $contributor ) use ( $stats_calculator, $event_start ) {
    201212                                        $append_tada = '';
    202                                         if ( $stats_calculator->is_first_time_contributor( $event_start, $contributor->ID ) ) {
     213                                        if ( $stats_calculator->is_new_translation_contributor( $event_start, $contributor->ID ) ) {
    203214                                            $append_tada = '<span class="first-time-contributor-tada" title="' . esc_html__( 'New Translation Contributor', 'gp-translation-events' ) . '"></span>';
    204215                                        }
Note: See TracChangeset for help on using the changeset viewer.