| 1 | <?php |
| 2 | $edit_link = gp_link_project_edit_get( $project, __( '(edit)' ) ); |
| 3 | |
| 4 | gp_title( sprintf( __( 'Translators < %s < GlotPress' ), esc_html( $project->name ) ) ); |
| 5 | gp_breadcrumb_project( $project ); |
| 6 | |
| 7 | wp_enqueue_script( 'common' ); |
| 8 | wp_enqueue_script( 'tablesorter' ); |
| 9 | |
| 10 | $translators_recent = $translators_total = $translators_minimum10 = $translators_minimum100 = 0; |
| 11 | foreach ( $project_translators as $locale_slug => $translators ) { |
| 12 | foreach ( $translators as $translator_id => $translations ) { |
| 13 | $translators_total += 1; |
| 14 | |
| 15 | if ( $translations->recent > 0 ) { |
| 16 | $translators_recent += 1; |
| 17 | } |
| 18 | if ( $translations->count >= 10 ) { |
| 19 | $translators_minimum10 += 1; |
| 20 | } |
| 21 | if ( $translations->count >= 100 ) { |
| 22 | $translators_minimum100 += 1; |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | gp_tmpl_header(); |
| 28 | ?> |
| 29 | |
| 30 | <div class="project-header"> |
| 31 | <p class="project-description"><?php echo apply_filters( 'project_description', $project->description, $project ); ?></p> |
| 32 | <div class="project-description"> |
| 33 | <a href="" id="translator-stats-toggle"><?php _e( 'Show translator stats »' ); ?></a> |
| 34 | |
| 35 | <ul id="translator-stats"> |
| 36 | <li><?php printf( _n( '%d people contributed translations to this project.', '%d people contributed translations to this project', $translators_total ), $translators_total ); ?></li> |
| 37 | |
| 38 | <?php if ( $translators_recent > 0 ): ?> |
| 39 | <li class="filter" data-filter="recent" data-filter-name="<?php echo esc_attr( __( 'only people who translated in the last year' ) ); ?>"><span><?php printf( _n( '%d person contributed translations in the last year.', '%d people contributed translations in the last year.', $translators_recent ), $translators_recent ); ?></span></li> |
| 40 | <?php endif; ?> |
| 41 | |
| 42 | <?php if ( $translators_minimum10 > 0 ): ?> |
| 43 | <li class="filter" data-filter="minimum10" data-filter-name="<?php echo esc_attr( __( 'only people who contributed at least 10 translations' ) ); ?>"><span><?php printf( _n( '%d person contributed at least 10 translations.', '%d people contributed at least 10 translations.', $translators_minimum10 ), $translators_minimum10 ); ?></span></li> |
| 44 | <?php endif; ?> |
| 45 | |
| 46 | <?php if ( $translators_minimum10 > 0 ): ?> |
| 47 | <li class="filter" data-filter="minimum100" data-filter-name="<?php echo esc_attr( __( 'only people who contributed at least 100 translations' ) ); ?>"><span><?php printf( _n( '%d person contributed at least 100 translations.', '%d people contributed at least 100 translations.', $translators_minimum100 ), $translators_minimum100 ); ?></span></li> |
| 48 | <?php endif; ?> |
| 49 | |
| 50 | </ul> |
| 51 | </div> |
| 52 | |
| 53 | |
| 54 | <div class="project-box"> |
| 55 | <div class="project-box-header"> |
| 56 | <div class="project-icon"> |
| 57 | <?php echo $project->icon; ?> |
| 58 | </div> |
| 59 | |
| 60 | <ul class="project-meta"> |
| 61 | <li class="project-name"><?php echo $project->name; ?> <?php echo $edit_link; ?></li> |
| 62 | </ul> |
| 63 | </div> |
| 64 | </div> |
| 65 | </div> |
| 66 | |
| 67 | <div class="stats-table"> |
| 68 | <table id="translators-table" class="table"> |
| 69 | <thead> |
| 70 | <tr> |
| 71 | <th class="locale"><?php echo _( 'Locale' ); ?> <span class="filter-name"></span></th> |
| 72 | <th class="username"><?php echo _( 'Username' ); ?></th> |
| 73 | <th class="translations"><?php echo _( 'Translations' ); ?></th> |
| 74 | <th class="translations"><?php echo _( 'Recent' ); ?></th> |
| 75 | </tr> |
| 76 | </thead> |
| 77 | <tbody> |
| 78 | <?php |
| 79 | foreach ( $project_translators as $locale_slug => $translators ) : |
| 80 | $gp_locale = GP_Locales::by_slug( $locale_slug ); |
| 81 | |
| 82 | $set_slug = 'default'; |
| 83 | |
| 84 | // Variants (de/formal for example) don't have GP_Locales in this context |
| 85 | if ( ! $gp_locale && ( list( $base_locale_slug, $set_slug ) = explode( '/', $locale_slug ) ) ) : |
| 86 | $gp_locale = clone GP_Locales::by_slug( $base_locale_slug ); |
| 87 | |
| 88 | // Just append it for now.. |
| 89 | $gp_locale->wp_locale .= '/' . $set_slug; |
| 90 | $gp_locale->english_name .= ' (' . ucfirst( $set_slug ) . ')'; |
| 91 | endif; |
| 92 | |
| 93 | if ( ! $gp_locale || ! $gp_locale->wp_locale ) : |
| 94 | continue; |
| 95 | endif; |
| 96 | |
| 97 | foreach ( $translators as $translator_id => $translations ): |
| 98 | $user = GP::$user->get( $translator_id ); |
| 99 | ?> |
| 100 | <tr> |
| 101 | <th title="<?php echo esc_attr( $gp_locale->wp_locale ); ?>"> |
| 102 | <a href="<?php echo gp_url( gp_url_join( 'locale', $gp_locale->slug, $set_slug, $project->path ) ); ?>"> |
| 103 | <?php echo esc_html( $gp_locale->english_name ); ?> |
| 104 | </a> |
| 105 | </th> |
| 106 | <td><?php echo $user->user_login; ?></td> |
| 107 | <td><?php echo $translations->count; ?></td> |
| 108 | <td><?php echo $translations->recent; ?></td> |
| 109 | </tr> |
| 110 | <?php endforeach; ?> |
| 111 | <?php endforeach; ?> |
| 112 | </tbody> |
| 113 | </table> |
| 114 | </div> |
| 115 | |
| 116 | <script type="text/javascript"> |
| 117 | jQuery( function( $ ) { |
| 118 | $( '#translators-table' ).tablesorter( { |
| 119 | textExtraction: function( node ) { |
| 120 | var cellValue = $( node ).text(), |
| 121 | sortValue = $( node ).data( 'sortValue' ); |
| 122 | |
| 123 | return ( undefined !== sortValue ) ? sortValue : cellValue; |
| 124 | } |
| 125 | }); |
| 126 | |
| 127 | $( '#translator-stats-toggle' ).on( 'click', function() { |
| 128 | $( '#translator-stats' ).toggle(); |
| 129 | return false; |
| 130 | }); |
| 131 | |
| 132 | $( '#translator-stats li.filter' ).on( 'click', function() { |
| 133 | var $this = $( this ), filter = $this.data( 'filter' ); |
| 134 | |
| 135 | if ( $this.hasClass( 'active' ) ) { |
| 136 | $( '#translators-table thead th.locale span.filter-name' ).text( '' ); |
| 137 | $( '#translators-table tbody tr').each( function() { |
| 138 | this.style.display = 'table-row'; |
| 139 | }); |
| 140 | $this.removeClass( 'active' ); |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | $this.addClass( 'active' ); |
| 145 | $( '#translators-table thead th.locale span.filter-name' ).text( '(' + $this.data( 'filter-name' ) + ')' ); |
| 146 | |
| 147 | if ( filter === 'recent' ) { |
| 148 | $( '#translators-table tbody tr').each( function() { |
| 149 | this.style.display = parseInt( $( this ).find( 'td' ).eq( 1 ).text(), 10 ) > 0 ? |
| 150 | 'table-row' : 'none'; |
| 151 | }); |
| 152 | } else if ( filter === 'minimum10' ) { |
| 153 | $( '#translators-table tbody tr').each( function() { |
| 154 | this.style.display = parseInt( $( this ).find( 'td' ).eq( 2 ).text(), 10 ) >= 10 ? |
| 155 | 'table-row' : 'none'; |
| 156 | }); |
| 157 | } else if ( filter === 'minimum100' ) { |
| 158 | $( '#translators-table tbody tr').each( function() { |
| 159 | this.style.display = parseInt( $( this ).find( 'td' ).eq( 2 ).text(), 10 ) >= 100 ? |
| 160 | 'table-row' : 'none'; |
| 161 | }); |
| 162 | } |
| 163 | return false; |
| 164 | }) |
| 165 | }); |
| 166 | </script> |
| 167 | |
| 168 | <?php gp_tmpl_footer(); |