[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/gp-templates/ -> translations.php (source)

   1  <?php
   2  gp_title( sprintf( __( 'Translations &lt; %s &lt; %s &lt; GlotPress', 'glotpress' ), $translation_set->name, $project->name ) );
   3  gp_breadcrumb( array(
   4      gp_project_links_from_root( $project ),
   5      gp_link_get( $url, $translation_set->name ),
   6  ) );
   7  gp_enqueue_scripts( array( 'gp-editor', 'gp-translations-page' ) );
   8  wp_localize_script( 'gp-translations-page', '$gp_translations_options', array( 'sort' => __( 'Sort', 'glotpress' ), 'filter' => __( 'Filter', 'glotpress' ) ) );
   9  
  10  // localizer adds var in front of the variable name, so we can't use $gp.editor.options
  11  $editor_options = compact( 'can_approve', 'can_write', 'url', 'discard_warning_url', 'set_priority_url', 'set_status_url', 'new_note_url', 'edit_note_url', 'delete_note_url' );
  12  
  13  wp_localize_script( 'gp-editor', '$gp_editor_options', $editor_options );
  14  
  15  gp_tmpl_header();
  16  $i = 0;
  17  ?>
  18  <h2>
  19      <?php printf( __( 'Translation of %s', 'glotpress' ), esc_html( $project->name )); ?>: <?php echo esc_html( $translation_set->name ); ?>
  20      <?php gp_link_set_edit( $translation_set, $project, __( '(edit)', 'glotpress' ) ); ?>
  21      <?php gp_link_set_delete( $translation_set, $project, __( '(delete)', 'glotpress' ) ); ?>
  22      <?php if ( $glossary && $glossary->translation_set_id === $translation_set->id ) : ?>
  23      <?php echo gp_link( $glossary->path(), __( 'Glossary', 'glotpress' ), array('class'=>'glossary-link') ); ?>
  24      <?php elseif ( $can_approve ): ?>
  25          <?php echo gp_link_get( gp_url( '/glossaries/-new', array( 'translation_set_id' => $translation_set->id ) ), __( 'Create Glossary', 'glotpress' ), array('class'=>'glossary-link') ); ?>
  26      <?php endif; ?>
  27  </h2>
  28  <?php
  29  if ( $can_approve ) {
  30      gp_translations_bulk_actions_toolbar( $bulk_action, $can_write, $translation_set, 'top' );
  31  }
  32  
  33  echo gp_pagination( $page, $per_page, $total_translations_count );
  34  ?>
  35  <div class="filter-toolbar">
  36      <form id="upper-filters-toolbar" class="filters-toolbar" action="" method="get" accept-charset="utf-8">
  37          <div>
  38          <a href="#" class="revealing filter"><?php _e( 'Filter &darr;', 'glotpress' ); ?></a> <span class="separator">&bull;</span>
  39          <a href="#" class="revealing sort"><?php _e( 'Sort &darr;', 'glotpress' ); ?></a> <strong class="separator">&bull;</strong>
  40          <?php
  41          $current_filter = '';
  42          $filter_links = array();
  43  
  44          // Use array_filter() to remove empty values, store them for use later if a custom filter has been applied.
  45          $filters_values_only = array_filter( $filters );
  46          $sort_values_only    = array_filter( $sort );
  47          $filters_and_sort    = array_merge( $filters_values_only, $sort_values_only );
  48  
  49          /**
  50           * Check to see if a term or user login has been added to the filter or one of the other filter options, if so,
  51           * we don't want to match the standard filter links.
  52           *
  53           * Note: Don't check for the warnings filter here otherwise we won't be able to use this value during the check
  54           * to see if the warnings filter link entry is the currently selected filter.
  55           */
  56          $additional_filters = array_key_exists( 'term', $filters_and_sort ) ||
  57                                  array_key_exists( 'user_login', $filters_and_sort ) ||
  58                                  array_key_exists( 'with_comment', $filters_and_sort ) ||
  59                                  array_key_exists( 'case_sensitive', $filters_and_sort ) ||
  60                                  array_key_exists( 'with_context', $filters_and_sort );
  61  
  62          // Because 'warnings' is not a translation status we need to know if we're filtering on it before we check
  63          // for what filter links to add.
  64          $warnings_filter = array_key_exists( 'warnings', $filters_and_sort );
  65  
  66          $all_filters = array(
  67              'status' => 'current_or_waiting_or_fuzzy_or_untranslated',
  68          );
  69  
  70          $current_filter_class = array(
  71              'class' => 'filter-current',
  72          );
  73  
  74          $is_current_filter = ( array() === array_diff( $all_filters, $filters_and_sort ) || array() === $filters_and_sort ) && ! $additional_filters && ! $warnings_filter;
  75          $current_filter    = $is_current_filter ? 'all' : $current_filter;
  76  
  77          $filter_links[] = gp_link_get(
  78              $url,
  79              // Translators: %s is the total strings count for the current translation set.
  80              sprintf( __( 'All&nbsp;(%s)', 'glotpress' ), number_format_i18n( $translation_set->all_count() ) ),
  81              $is_current_filter ? $current_filter_class : array()
  82          );
  83  
  84          $untranslated_filters = array(
  85              'filters[status]' => 'untranslated',
  86              'sort[by]'        => 'priority',
  87              'sort[how]'       => 'desc',
  88          );
  89  
  90          $is_current_filter = array() === array_diff( $untranslated_filters, $filters_and_sort ) && false === $additional_filters && ! $warnings_filter;
  91          $current_filter    = $is_current_filter ? 'untranslated' : $current_filter;
  92  
  93          $filter_links[] = gp_link_get(
  94              add_query_arg( $untranslated_filters, $url ),
  95              // Translators: %s is the untranslated strings count for the current translation set.
  96              sprintf( __( 'Untranslated&nbsp;(%s)', 'glotpress' ), number_format_i18n( $translation_set->untranslated_count() ) ),
  97              $is_current_filter ? $current_filter_class : array()
  98          );
  99  
 100          $waiting_filters = array(
 101              'filters[translated]' => 'yes',
 102              'filters[status]'     => 'waiting',
 103          );
 104  
 105          $is_current_filter = array() === array_diff( $waiting_filters, $filters_and_sort ) && ! $additional_filters && ! $warnings_filter;
 106          $current_filter    = $is_current_filter ? 'waiting' : $current_filter;
 107  
 108          $filter_links[] = gp_link_get(
 109              add_query_arg( $waiting_filters, $url ),
 110              // Translators: %s is the waiting strings count for the current translation set.
 111              sprintf( __( 'Waiting&nbsp;(%s)', 'glotpress' ), number_format_i18n( $translation_set->waiting_count() ) ),
 112              $is_current_filter ? $current_filter_class : array()
 113          );
 114  
 115          $fuzzy_filters = array(
 116              'filters[translated]' => 'yes',
 117              'filters[status]'     => 'fuzzy',
 118          );
 119  
 120          $is_current_filter = array() === array_diff( $fuzzy_filters, $filters_and_sort ) && ! $additional_filters && ! $warnings_filter;
 121          $current_filter    = $is_current_filter ? 'fuzzy' : $current_filter;
 122  
 123          $filter_links[] = gp_link_get(
 124              add_query_arg( $fuzzy_filters, $url ),
 125              // Translators: %s is the fuzzy strings count for the current translation set.
 126              sprintf( __( 'Fuzzy&nbsp;(%s)', 'glotpress' ), number_format_i18n( $translation_set->fuzzy_count() ) ),
 127              $is_current_filter ? $current_filter_class : array()
 128          );
 129  
 130          $warning_filters = array(
 131              'filters[warnings]' => 'yes',
 132          );
 133  
 134          $is_current_filter = array() === array_diff( $warning_filters, $filters_and_sort ) && ! $additional_filters && ! array_key_exists( 'status', $filters_and_sort );
 135          $current_filter    = $is_current_filter ? 'warning' : $current_filter;
 136  
 137          $filter_links[] = gp_link_get(
 138              add_query_arg( $warning_filters, $url ),
 139              // Translators: %s is the strings with warnings count for the current translation set.
 140              sprintf( __( 'Warnings&nbsp;(%s)', 'glotpress' ), number_format_i18n( $translation_set->warnings_count() ) ),
 141              $is_current_filter ? $current_filter_class : array()
 142          );
 143  
 144          // If no filter has been selected yet, then add the current filter count to the end of the filter links array.
 145          if ( '' === $current_filter ) {
 146              // Build an array or query args to add to the link using the current sort/filter options.
 147              $custom_filter = array();
 148  
 149              foreach ( $filters_values_only as $key => $value ) {
 150                  $custom_filter[ 'filters[' . $key . ']' ] = $value;
 151              }
 152  
 153              foreach ( $sort_values_only as $key => $value ) {
 154                  $custom_filter[ 'sort[' . $key . ']' ] = $value;
 155              }
 156  
 157              $filter_links[] = gp_link_get(
 158                  add_query_arg( $custom_filter, $url ),
 159                  // Translators: %s is the strings with the current filter count for the current translation set.
 160                  sprintf( __( 'Current&nbsp;Filter&nbsp;(%s)', 'glotpress' ), number_format_i18n( $total_translations_count ) ),
 161                  $current_filter_class
 162              );
 163          }
 164  
 165          // TODO: saved searches.
 166          echo implode( ' <span class="separator">&bull;</span> ', $filter_links ); // WPCS: XSS ok.
 167          ?>
 168          </div>
 169          <dl class="filters-expanded filters hidden clearfix">
 170              <dd>
 171                  <label for="filters[term]" class="filter-title"><?php _e( 'Term:', 'glotpress' ); // WPCS: XSS ok. ?></label><br />
 172                  <input type="text" value="<?php echo gp_esc_attr_with_entities( gp_array_get( $filters, 'term' ) ); // WPCS: XSS ok. ?>" name="filters[term]" id="filters[term]" /><br />
 173                  <label for="filters[term_scope]" class="filter-title"><?php _e( 'Term Scope:', 'glotpress' ); // WPCS: XSS ok. ?></label><br />
 174                  <?php
 175                      echo gp_radio_buttons( // WPCS: XSS ok.
 176                          'filters[term_scope]',
 177                          array(
 178                              'scope_originals'    => __( 'Originals only', 'glotpress' ),
 179                              'scope_translations' => __( 'Translations only', 'glotpress' ),
 180                              'scope_context'      => __( 'Context only', 'glotpress' ),
 181                              'scope_references'   => __( 'References only', 'glotpress' ),
 182                              'scope_both'         => __( 'Both Originals and Translations', 'glotpress' ),
 183                              'scope_any'          => __( 'Any', 'glotpress' ),
 184                          ),
 185                          gp_array_get( $filters, 'term_scope', 'scope_any' )
 186                      );
 187                  ?>
 188              </dd>
 189              <dd>
 190                  <label class="filter-title"><?php _e( 'Status:', 'glotpress' ); // WPCS: XSS ok. ?></label><br />
 191                  <?php
 192                      echo gp_radio_buttons(
 193                          'filters[status]', // TODO: show only these, which user is allowed to see afterwards.
 194                          array(
 195                              'current_or_waiting_or_fuzzy_or_untranslated' => __( 'Current/waiting/fuzzy + untranslated (All)', 'glotpress' ),
 196                              'current' => __( 'Current only', 'glotpress' ),
 197                              'old' => __( 'Approved, but obsoleted by another translation', 'glotpress' ),
 198                              'waiting' => __( 'Waiting approval', 'glotpress' ),
 199                              'rejected' => __( 'Rejected', 'glotpress' ),
 200                              'untranslated' => __( 'Without current translation', 'glotpress' ),
 201                              'either' => __( 'Any', 'glotpress' ),
 202                          ),
 203                          gp_array_get( $filters, 'status', 'current_or_waiting_or_fuzzy_or_untranslated' )
 204                      );
 205                  ?>
 206              </dd>
 207              <dd>
 208                  <label class="filter-title"><?php _e( 'Options:', 'glotpress' ); // WPCS: XSS ok. ?></label><br />
 209                  <input type="checkbox" name="filters[with_comment]" value="yes" id="filters[with_comment][yes]" <?php gp_checked( 'yes' === gp_array_get( $filters, 'with_comment' ) ); ?>><label for='filters[with_comment][yes]'><?php _e( 'With comment', 'glotpress' ); ?></label><br />
 210                  <input type="checkbox" name="filters[with_context]" value="yes" id="filters[with_context][yes]" <?php gp_checked( 'yes' === gp_array_get( $filters, 'with_context' ) ); ?>><label for='filters[with_context][yes]'><?php _e( 'With context', 'glotpress' ); ?></label><br />
 211                  <input type="checkbox" name="filters[case_sensitive]" value="yes" id="filters[case_sensitive][yes]" <?php gp_checked( 'yes' === gp_array_get( $filters, 'case_sensitive' ) ); ?>><label for='filters[case_sensitive][yes]'><?php _e( 'Case sensitive', 'glotpress' ); // WPCS: XSS ok. ?></label><br />
 212                  <input type="checkbox" name="filters[warnings]" value="yes" id="filters[warnings][yes]" <?php gp_checked( 'yes' === gp_array_get( $filters, 'warnings' ) ); ?>><label for='filters[warnings][yes]'><?php _e( 'With warnings', 'glotpress' ); // WPCS: XSS ok. ?></label><br />
 213                  <label for="filters[user_login]" class="filter-title"><?php _e( 'User:', 'glotpress' ); // WPCS: XSS ok. ?></label><br />
 214                  <input type="text" value="<?php echo gp_esc_attr_with_entities( gp_array_get( $filters, 'user_login' ) ); // WPCS: XSS ok. ?>" name="filters[user_login]" id="filters[user_login]" /><br />
 215              </dd>
 216              <?php
 217  
 218              /**
 219               * Fires after the translation set filters options.
 220               *
 221               * This action is inside a DL element.
 222               *
 223               * @since 2.1.0
 224               */
 225              do_action( 'gp_translation_set_filters_form' );
 226              ?>
 227  
 228              <dd><input type="submit" value="<?php esc_attr_e( 'Filter', 'glotpress' ); ?>" name="filter" /></dd>
 229          </dl>
 230          <dl class="filters-expanded sort hidden clearfix">
 231              <dt><?php _x( 'By:', 'sort by', 'glotpress' ); ?></dt>
 232              <dd>
 233              <?php
 234              $default_sort = get_user_option( 'gp_default_sort' );
 235              if ( ! is_array( $default_sort ) ) {
 236                  $default_sort = array(
 237                      'by'  => 'priority',
 238                      'how' => 'desc',
 239                  );
 240              }
 241  
 242              $sort_bys = wp_list_pluck( gp_get_sort_by_fields(), 'title' );
 243  
 244              echo gp_radio_buttons( 'sort[by]', $sort_bys, gp_array_get( $sort, 'by', $default_sort['by'] ) );
 245              ?>
 246              </dd>
 247              <dt><?php _e( 'Order:', 'glotpress' ); ?></dt>
 248              <dd>
 249              <?php
 250              echo gp_radio_buttons(
 251                  'sort[how]',
 252                  array(
 253                      'asc' => __( 'Ascending', 'glotpress' ),
 254                      'desc' => __( 'Descending', 'glotpress' ),
 255                  ),
 256                  gp_array_get( $sort, 'how', $default_sort['how'] )
 257              );
 258              ?>
 259              </dd>
 260              <?php
 261  
 262              /**
 263               * Fires after the translation set sort options.
 264               *
 265               * This action is inside a DL element.
 266               *
 267               * @deprecated 2.1.0 Call gp_translation_set_sort_form instead
 268               * @since 1.0.0
 269               */
 270              do_action( 'gp_translation_set_filters' );
 271  
 272              /**
 273               * Fires after the translation set sort options.
 274               *
 275               * This action is inside a DL element.
 276               *
 277               * @since 2.1.0
 278               */
 279              do_action( 'gp_translation_set_sort_form' );
 280              ?>
 281  
 282              <dd><input type="submit" value="<?php esc_attr_e( 'Sort', 'glotpress' ); ?>" name="sorts" /></dd>
 283          </dl>
 284      </form>
 285  </div>
 286  
 287  <table id="translations" class="translations clear<?php if ( 'rtl' == $locale->text_direction ) { echo ' translation-sets-rtl'; } ?>">
 288      <thead>
 289      <tr>
 290          <?php if ( $can_approve ) : ?><th class="checkbox"><input type="checkbox" /></th><?php endif; ?>
 291          <th class="priority"><?php /* Translators: Priority */ _e( 'Prio', 'glotpress' ); ?></th>
 292          <th class="original"><?php _e( 'Original string', 'glotpress' ); ?></th>
 293          <th class="translation"><?php _e( 'Translation', 'glotpress' ); ?></th>
 294          <th class="actions">&mdash;</th>
 295      </tr>
 296      </thead>
 297  <?php
 298      if ( $glossary ) {
 299          $glossary_entries       = $glossary->get_entries();
 300          $glossary_entries_terms = gp_sort_glossary_entries_terms( $glossary_entries );
 301      }
 302  
 303      $root_locale          = null;
 304      $root_translation_set = null;
 305      $has_root             = null;
 306  
 307      if ( null !== $locale->variant_root ) {
 308          $root_locale          = GP_Locales::by_slug( $locale->variant_root );
 309          $root_translation_set = GP::$translation_set->by_project_id_slug_and_locale( $project->id, $translation_set->slug, $locale->variant_root );
 310  
 311          // Only set the root tranlsation flag if we have a valid root translation set, otherwise there's no point in querying it later.
 312          if ( null !== $root_translation_set ) {
 313              $has_root = true;
 314          }
 315      }
 316  
 317      foreach ( $translations as $translation ) {
 318          if ( ! $translation->translation_set_id ) {
 319              $translation->translation_set_id = $translation_set->id;
 320          }
 321  
 322      $can_approve_translation = GP::$permission->current_user_can( 'approve', 'translation', $translation->id, array( 'translation' => $translation ) );
 323      gp_tmpl_load( 'translation-row', get_defined_vars() );
 324  }
 325  ?>
 326  <?php
 327      if ( ! $translations ) :
 328  ?>
 329      <tr><td colspan="<?php echo $can_approve ? 5 : 4; ?>"><?php _e( 'No translations were found!', 'glotpress' ); ?></td></tr>
 330  <?php
 331      endif;
 332  ?>
 333  </table>
 334  <?php
 335  if ( $can_approve ) {
 336      gp_translations_bulk_actions_toolbar( $bulk_action, $can_write, $translation_set, 'bottom' );
 337  }
 338  
 339  echo gp_pagination( $page, $per_page, $total_translations_count );
 340  ?>
 341  <div id="legend" class="secondary clearfix">
 342      <div><strong><?php _e( 'Legend:', 'glotpress' ); ?></strong></div>
 343  <?php
 344      foreach ( GP::$translation->get_static( 'statuses' ) as $legend_status ) :
 345  ?>
 346      <div class="box status-<?php echo esc_attr( $legend_status ); ?>"></div>
 347      <div>
 348  <?php
 349          switch ( $legend_status ) {
 350              case 'current':
 351                  _e( 'Current', 'glotpress' );
 352                  break;
 353              case 'waiting':
 354                  _e( 'Waiting', 'glotpress' );
 355                  break;
 356              case 'fuzzy':
 357                  _e( 'Fuzzy', 'glotpress' );
 358                  break;
 359              case 'old':
 360                  _e( 'Old', 'glotpress' );
 361                  break;
 362              case 'rejected':
 363                  _e( 'Rejected', 'glotpress' );
 364                  break;
 365              default:
 366                  echo esc_html( $legend_status );
 367          }
 368  ?>
 369      </div><?php endforeach; ?>
 370      <div class="box has-warnings"></div>
 371      <div><?php _e( 'With warnings', 'glotpress' ); ?></div>
 372  <?php
 373      if ( $locale->variant_root ) :
 374  ?>
 375      <div class="box root-translation"></div>
 376      <div><?php _e( 'Root translation', 'glotpress' ); // phpcs:ignore WordPress.Security.EscapeOutput. ?></div>
 377  <?php
 378      endif
 379  ?>
 380  </div>
 381  <p class="clear actionlist secondary">
 382      <?php
 383          $footer_links = array();
 384          if ( ( isset( $can_import_current ) && $can_import_current ) || ( isset( $can_import_waiting ) && $can_import_waiting ) ) {
 385              $footer_links[] = gp_link_get( gp_url_project( $project, array( $locale->slug, $translation_set->slug, 'import-translations' ) ), __( 'Import Translations', 'glotpress' ) );
 386          }
 387  
 388          /**
 389           * The 'default' filter is 'Current/waiting/fuzzy + untranslated (All)', however that is not
 390           * the default action when exporting so make sure to set it on the export link if no filter
 391           * has been activated by the user.
 392           */
 393          if ( ! array_key_exists( 'status', $filters ) ) {
 394              $filters['status'] = 'current_or_waiting_or_fuzzy_or_untranslated';
 395          }
 396  
 397          $export_url = gp_url_project( $project, array( $locale->slug, $translation_set->slug, 'export-translations' ) );
 398          $export_link = gp_link_get( $export_url , __( 'Export', 'glotpress' ), array('id' => 'export', 'filters' => add_query_arg( array( 'filters' => $filters ), $export_url ) ) );
 399          $format_options = array();
 400          foreach ( GP::$formats as $slug => $format ) {
 401              $format_options[$slug] = $format->name;
 402          }
 403          $what_dropdown = gp_select( 'what-to-export', array('all' => _x( 'all current', 'export choice', 'glotpress' ), 'filtered' => _x( 'only matching the filter', 'export choice', 'glotpress' ) ), 'all' );
 404          $format_dropdown = gp_select( 'export-format', $format_options, 'po' );
 405          /* translators: 1: export 2: what to export dropdown (all/filtered) 3: export format */
 406          $footer_links[] = sprintf( __( '%1$s %2$s as %3$s', 'glotpress' ), $export_link, $what_dropdown, $format_dropdown );
 407  
 408          /**
 409           * Filter footer links in translations.
 410           *
 411           * @since 1.0.0
 412           *
 413           * @param array              $footer_links    Default links.
 414           * @param GP_Project         $project         The current project.
 415           * @param GP_Locale          $locale          The current locale.
 416           * @param GP_Translation_Set $translation_set The current translation set.
 417           */
 418          echo implode( ' &bull; ', apply_filters( 'gp_translations_footer_links', $footer_links, $project, $locale, $translation_set ) );
 419      ?>
 420  </p>
 421  <?php gp_tmpl_footer();


Generated: Sun Jun 16 01:02:50 2019 Cross-referenced by PHPXref 0.7.1