Making WordPress.org


Ignore:
Timestamp:
05/09/2024 08:33:51 AM (2 years ago)
Author:
amieiro
Message:

Translate: Sync "Translation Events" from GitHub

File:
1 edited

Legend:

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

    r13566 r13683  
    99use WP_User;
    1010use Wporg\TranslationEvents\Attendee\Attendee;
    11 use Wporg\TranslationEvents\Attendee\Attendee_Repository;
    1211use Wporg\TranslationEvents\Event\Event;
    1312use Wporg\TranslationEvents\Event\Event_End_Date;
     
    1615use Wporg\TranslationEvents\Stats\Stats_Row;
    1716
    18 /** @var Attendee_Repository $attendee_repo */
    19 /** @var Attendee $attendee */
     17/** @var bool $user_is_attending */
     18/** @var bool $user_is_contributor */
     19/** @var Attendee[] $attendees_not_contributing */
     20/** @var Attendee[] $contributors */
     21/** @var array $new_contributor_ids */
    2022/** @var Event $event */
    2123/** @var int $event_id */
     
    5355                                <ul>
    5456                                        <?php foreach ( $contributors as $contributor ) : ?>
    55                                                 <li class="event-contributor" title="<?php echo esc_html( implode( ', ', $contributor->locales ) ); ?>">
    56                                                         <a href="<?php echo esc_url( get_author_posts_url( $contributor->ID ) ); ?>" class="avatar"><?php echo get_avatar( $contributor->ID, 48 ); ?></a>
    57                                                         <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>
    58                                                         <?php if ( $stats_calculator->is_new_translation_contributor( $event_start, $contributor->ID ) ) : ?>
     57                                                <li class="event-contributor" title="<?php echo esc_html( implode( ', ', $contributor->contributed_locales() ) ); ?>">
     58                                                        <a href="<?php echo esc_url( get_author_posts_url( $contributor->user_id() ) ); ?>" class="avatar"><?php echo get_avatar( $contributor->user_id(), 48 ); ?></a>
     59                                                        <a href="<?php echo esc_url( get_author_posts_url( $contributor->user_id() ) ); ?>" class="name"><?php echo esc_html( get_the_author_meta( 'display_name', $contributor->user_id() ) ); ?></a>
     60                                                        <?php if ( isset( $new_contributor_ids[ $contributor->user_id() ] ) ) : ?>
    5961                                                                <span class="first-time-contributor-tada" title="<?php esc_html_e( 'New Translation Contributor', 'gp-translation-events' ); ?>"></span>
    6062                                                        <?php endif; ?>
    61                                                         <?php
    62                                                         if ( ! $event->end()->is_in_the_past() ) :
    63                                                                 if ( ( $attendee instanceof Attendee && $attendee->is_host() ) || current_user_can( 'manage_options' ) || $user->ID === $event->author_id() ) :
    64                                                                         $_attendee = $attendee_repo->get_attendee( $event_id, $contributor->ID );
    65                                                                         if ( $_attendee instanceof Attendee ) :
    66                                                                                 echo '<form class="add-remove-user-as-host" method="post" action="' . esc_url( gp_url( "/events/host/$event_id/$contributor->ID" ) ) . '">';
    67                                                                                 if ( $_attendee->is_host() ) :
    68                                                                                         echo '<input type="submit" class="button is-primary remove-as-host" value="Remove as host"/>';
    69                                                                                 else :
    70                                                                                         echo '<input type="submit" class="button is-secondary convert-to-host" value="Make co-host"/>';
    71                                                                                 endif;
    72                                                                                 echo '</form>';
    73                                                                         else :
    74                                                                                 echo '<span class="event-not-attending">' . esc_html__( 'Not attending', 'gp-translation-events' ) . '</span>';
    75                                                                         endif;
    76                                                                 endif;
    77                                                         endif;
    78                                                         ?>
    7963                                                </li>
    8064                                        <?php endforeach; ?>
     
    8266                        </div>
    8367                <?php endif; ?>
    84                 <?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() ) ) ) : ?>
     68                <?php if ( ! empty( $attendees_not_contributing ) && current_user_can( 'edit_translation_event', $event->id() ) ) : ?>
    8569                        <div class="event-attendees">
    8670                                <h2>
    8771                                <?php
    8872                                // translators: %d is the number of attendees.
    89                                 echo esc_html( sprintf( __( 'Attendees (%d)', 'gp-translation-events' ), number_format_i18n( count( $attendees ) ) ) );
     73                                echo esc_html( sprintf( __( 'Attendees (%d)', 'gp-translation-events' ), number_format_i18n( count( $attendees_not_contributing ) ) ) );
    9074                                ?>
    9175                                </h2>
    9276                                <ul>
    93                                         <?php foreach ( $attendees as $_user ) : ?>
     77                                        <?php foreach ( $attendees_not_contributing as $_attendee ) : ?>
    9478                                                <li class="event-attendee">
    95                                                         <a href="<?php echo esc_url( get_author_posts_url( $_user->ID ) ); ?>" class="avatar"><?php echo get_avatar( $_user->ID, 48 ); ?></a>
    96                                                         <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>
    97                                                         <?php if ( $stats_calculator->is_new_translation_contributor( $event_start, $_user->ID ) ) : ?>
     79                                                        <a href="<?php echo esc_url( get_author_posts_url( $_attendee->user_id() ) ); ?>" class="avatar"><?php echo get_avatar( $_attendee->user_id(), 48 ); ?></a>
     80                                                        <a href="<?php echo esc_url( get_author_posts_url( $_attendee->user_id() ) ); ?>" class="name"><?php echo esc_html( get_the_author_meta( 'display_name', $_attendee->user_id() ) ); ?></a>
     81                                                        <?php if ( isset( $new_contributor_ids[ $_attendee->user_id() ] ) ) : ?>
    9882                                                                <span class="first-time-contributor-tada" title="<?php esc_html_e( 'New Translation Contributor', 'gp-translation-events' ); ?>"></span>
    9983                                                        <?php endif; ?>
    100                                                         <?php
    101                                                         if ( ! $event->end()->is_in_the_past() ) :
    102                                                                 if ( ( $attendee instanceof Attendee && $attendee->is_host() ) || current_user_can( 'manage_options' ) || $user->ID === $event->author_id() ) :
    103                                                                         $_attendee = $attendee_repo->get_attendee( $event_id, $_user->ID );
    104                                                                         if ( $_attendee instanceof Attendee ) :
    105                                                                                 echo '<form class="add-remove-user-as-host" method="post" action="' . esc_url( gp_url( "/events/host/$event_id/$_user->ID" ) ) . '">';
    106                                                                                 if ( $_attendee->is_host() ) :
    107                                                                                         echo '<input type="submit" class="button is-primary remove-as-host" value="Remove as host"/>';
    108                                                                                 else :
    109                                                                                         echo '<input type="submit" class="button is-secondary convert-to-host" value="Make co-host"/>';
    110                                                                                 endif;
    111                                                                                 echo '</form>';
    112                                                                         endif;
    113                                                                 endif;
    114                                                         endif;
    115                                                         ?>
    11684                                                </li>
    11785                                        <?php endforeach; ?>
     
    12593                                        <thead>
    12694                                        <tr>
    127                                                 <th scope="col">Locale</th>
    128                                                 <th scope="col">Translations created</th>
    129                                                 <th scope="col">Translations reviewed</th>
    130                                                 <th scope="col">Contributors</th>
     95                                                <th scope="col"><?php esc_html_e( 'Translations', 'gp-translation-events' ); ?></th>
     96                                                <th scope="col"><?php esc_html_e( 'Created', 'gp-translation-events' ); ?></th>
     97                                                <th scope="col"><?php esc_html_e( 'Waiting', 'gp-translation-events' ); ?></th>
     98                                                <th scope="col"><?php esc_html_e( 'Reviewed', 'gp-translation-events' ); ?></th>
     99                                                <th scope="col"><?php esc_html_e( 'Contributors', 'gp-translation-events' ); ?></th>
    131100                                        </tr>
    132101                                        </thead>
     
    136105                                        <tr>
    137106                                                <td title="<?php echo esc_html( $_locale ); ?> "><a href="<?php echo esc_url( gp_url_join( gp_url( '/languages' ), $row->language->slug ) ); ?>"><?php echo esc_html( $row->language->english_name ); ?></a></td>
    138                                                 <td><?php echo esc_html( $row->created ); ?></td>
     107                                                <td><a href="<?php echo esc_url( Urls::event_translations( $event->id(), $row->language->slug ) ); ?>"><?php echo esc_html( $row->created ); ?></a></td>
     108                                                <td><a href="<?php echo esc_url( Urls::event_translations( $event->id(), $row->language->slug, 'waiting' ) ); ?>"><?php echo esc_html( $row->waiting ); ?></a></td>
    139109                                                <td><?php echo esc_html( $row->reviewed ); ?></td>
    140110                                                <td><?php echo esc_html( $row->users ); ?></td>
     
    144114                                                <td>Total</td>
    145115                                                <td><?php echo esc_html( $event_stats->totals()->created ); ?></td>
     116                                                <td><?php echo esc_html( $event_stats->totals()->waiting ); ?></td>
    146117                                                <td><?php echo esc_html( $event_stats->totals()->reviewed ); ?></td>
    147118                                                <td><?php echo esc_html( $event_stats->totals()->users ); ?></td>
     
    155126                                        <?php foreach ( $projects as $project_name => $row ) : ?>
    156127                                        <li class="event-project" title="<?php echo esc_html( str_replace( ',', ', ', $row->locales ) ); ?>">
    157                                                 <a href="<?php echo esc_url( gp_url_project( $row->project ) ); ?>"><?php echo esc_html( $project_name ); ?></a> <small> to
    158128                                                <?php
     129                                                $row_locales = array();
    159130                                                foreach ( explode( ',', $row->locales ) as $_locale ) {
    160                                                         $_locale = GP_Locales::by_slug( $_locale );
    161                                                         ?>
    162                                                         <a href="<?php echo esc_url( gp_url_project_locale( $row->project, $_locale->slug, 'default' ) ); ?>"><?php echo esc_html( $_locale->english_name ); ?></a>
    163                                                         <?php
     131                                                        $_locale       = GP_Locales::by_slug( $_locale );
     132                                                        $row_locales[] = '<a href="' . esc_url( gp_url_project_locale( $row->project, $_locale->slug, 'default' ) ) . '">' . esc_html( $_locale->english_name ) . '</a>';
    164133                                                }
    165                                                 // translators: %d: Number of contributors.
    166                                                 echo esc_html( sprintf( _n( 'by %d contributor', 'by %d contributors', $row->users, 'gp-translation-events' ), $row->users ) );
     134                                                echo wp_kses_post(
     135                                                        wp_sprintf(
     136                                                                // translators: 1: Project translated. 2: List of languages. 3: Number of contributors.
     137                                                                _n(
     138                                                                        '%1$s <small>to %2$l by %3$d contributor</small>',
     139                                                                        '%1$s <small>to %2$l by %3$d contributors</small>',
     140                                                                        $row->users,
     141                                                                        'gp-translation-events'
     142                                                                ),
     143                                                                '<a href="' . esc_url( gp_url_project( $row->project ) ) . '">' . esc_html( $project_name ) . '</a>',
     144                                                                $row_locales,
     145                                                                $row->users
     146                                                        )
     147                                                );
    167148                                                ?>
    168                                                 </small>
    169149                                        </li>
    170150                                <?php endforeach; ?>
     
    175155                                <p class="event-stats-text">
    176156                                        <?php
    177                                         $new_contributors = array_filter(
    178                                                 $contributors,
    179                                                 function ( $contributor ) use ( $stats_calculator, $event_start ) {
    180                                                         return $stats_calculator->is_new_translation_contributor( $event_start, $contributor->ID );
    181                                                 }
    182                                         );
    183 
    184157                                        $new_contributors_text = '';
    185                                         if ( ! empty( $new_contributors ) ) {
     158                                        if ( ! empty( $new_contributor_ids ) ) {
    186159                                                $new_contributors_text = sprintf(
    187160                                                        // translators: %d is the number of new contributors.
    188                                                         _n( '(%d new contributor ๐ŸŽ‰)', '(%d new contributors ๐ŸŽ‰)', count( $new_contributors ), 'gp-translation-events' ),
    189                                                         count( $new_contributors )
     161                                                        _n( '(%d new contributor ๐ŸŽ‰)', '(%d new contributors ๐ŸŽ‰)', count( $new_contributor_ids ), 'gp-translation-events' ),
     162                                                        count( $new_contributor_ids )
    190163                                                );
    191164                                        }
    192165
    193166                                        echo wp_kses(
    194                                                 sprintf(
    195                                                         // translators: %1$s: Event title, %2$d: Number of contributors, %3$s: is a parenthesis with potential text "x new contributors", %4$d: Number of languages, %5$s: List of languages, %6$d: Number of strings translated, %7$d: Number of strings reviewed.
    196                                                         __( 'At the <strong>%1$s</strong> event, we had %2$d people %3$s who contributed in %4$d languages (%5$s), translated %6$d strings and reviewed %7$d strings.', 'gp-translation-events' ),
     167                                                wp_sprintf(
     168                                                        // translators: %1$s: Event title, %2$d: Number of contributors, %3$s: is a parenthesis with potential text "x new contributors", %4$d: Number of languages, %5$l: List of languages, %6$d: Number of strings translated, %7$d: Number of strings reviewed.
     169                                                        __( 'At the <strong>%1$s</strong> event, we had %2$d people %3$s who contributed in %4$d languages (%5$l), translated %6$d strings and reviewed %7$d strings.', 'gp-translation-events' ),
    197170                                                        esc_html( $event_title ),
    198171                                                        esc_html( $event_stats->totals()->users ),
    199172                                                        $new_contributors_text,
    200173                                                        count( $event_stats->rows() ),
    201                                                         esc_html(
    202                                                                 implode(
    203                                                                         ', ',
    204                                                                         array_map(
    205                                                                                 function ( $row ) {
    206                                                                                         return $row->language->english_name;
    207                                                                                 },
    208                                                                                 $event_stats->rows()
    209                                                                         )
    210                                                                 )
     174                                                        array_map(
     175                                                                function ( $row ) {
     176                                                                        return $row->language->english_name;
     177                                                                },
     178                                                                $event_stats->rows()
    211179                                                        ),
    212180                                                        esc_html( $event_stats->totals()->created ),
     
    220188                                        <?php
    221189                                        echo wp_kses(
    222                                                 sprintf(
    223                                                 // translators: %s the contributors.
    224                                                         esc_html__( 'Contributors were %s.', 'gp-translation-events' ),
    225                                                         implode(
    226                                                                 ', ',
    227                                                                 array_map(
    228                                                                         function ( $contributor ) use ( $stats_calculator, $event_start ) {
    229                                                                                 $append_tada = '';
    230                                                                                 if ( $stats_calculator->is_new_translation_contributor( $event_start, $contributor->ID ) ) {
     190                                                wp_sprintf(
     191                                                        // translators: %s List of contributors.
     192                                                        _n(
     193                                                                'Contributor was %l.',
     194                                                                'Contributors were %l.',
     195                                                                count( $contributors ),
     196                                                                'gp-translation-events'
     197                                                        ),
     198                                                        array_map(
     199                                                                function ( $contributor ) {
     200                                                                        $append_tada = '';
     201                                                                        if ( isset( $new_contributor_ids[ $contributor->user_id() ] ) ) {
    231202                                                                                        $append_tada = ' <span class="new-contributor" title="' . esc_html__( 'New Translation Contributor', 'gp-translation-events' ) . '">๐ŸŽ‰</span>';
    232                                                                                 }
    233                                                                                 return '@' . $contributor->user_login . $append_tada;
    234                                                                         },
    235                                                                         $contributors
    236                                                                 )
     203                                                                        }
     204                                                                        return '@' . ( new WP_User( $contributor->user_id() ) )->user_login . $append_tada;
     205                                                                },
     206                                                                $contributors
    237207                                                        )
    238208                                                ),
     
    268238                <div class="event-details-join">
    269239                        <?php if ( $event_end->is_in_the_past() ) : ?>
    270                                 <?php if ( $attendee instanceof Attendee ) : ?>
     240                                <?php if ( $user_is_attending ) : ?>
    271241                                        <button disabled="disabled" class="button is-primary attend-btn"><?php esc_html_e( 'You attended', 'gp-translation-events' ); ?></button>
    272242                                <?php endif; ?>
     243                        <?php elseif ( $user_is_contributor ) : ?>
     244                                <?php // Contributors can't un-attend so don't show anything. ?>
    273245                        <?php else : ?>
    274                                 <form class="event-details-attend" method="post" action="<?php echo esc_url( gp_url( "/events/attend/$event_id" ) ); ?>">
    275                                         <?php if ( $attendee instanceof Attendee ) : ?>
    276                                                 <input type="submit" class="button is-secondary attending-btn" value="You're attending" />
     246                                <form class="event-details-attend" method="post" action="<?php echo esc_url( Urls::event_toggle_attendee( $event_id ) ); ?>">
     247                                        <?php if ( $user_is_attending ) : ?>
     248                                                <input type="submit" class="button is-secondary attending-btn" value="<?php esc_attr_e( "You're attending", 'gp-translation-events' ); ?>" />
    277249                                        <?php else : ?>
    278                                                 <input type="submit" class="button is-primary attend-btn" value="Attend Event"/>
     250                                                <input type="submit" class="button is-primary attend-btn" value="<?php esc_attr_e( 'Attend Event', 'gp-translation-events' ); ?>"/>
    279251                                        <?php endif; ?>
    280252                                </form>
Note: See TracChangeset for help on using the changeset viewer.