WordPress.org

Making WordPress.org

Changeset 6006


Ignore:
Timestamp:
10/07/2017 01:23:36 PM (2 years ago)
Author:
ocean90
Message:

Translate, Consistency: Support filtering by parent projects and group results by translation.

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

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/consistency.php

    r3117 r6006  
    1111
    1212
    13 <form action="" method="get" class="consistency-form">
    14     <p>
    15         <input type="text" name="search" required value="<?php echo gp_esc_attr_with_entities( $search ); ?>" class="consistency-form-search" placeholder="Enter original to search for&hellip;">
    16         <?php
    17         $options     = [];
    18         $options[''] = 'Select a locale';
    19         $options     = array_merge( $options, $sets );
    20         echo gp_select( 'set', $options, $set, [ 'class' => 'consistency-form-locale', 'required' => 'required' ] );
    21         ?>
    22         <button type="submit" class="consistency-form-submit">Search</button>
     13<form action="/consistency" method="get" class="consistency-form">
     14    <p class="consistency-fields">
     15        <span class="consistency-field">
     16            <label for="original">Original</label>
     17            <input id="original" type="text" name="search" required value="<?php echo gp_esc_attr_with_entities( $search ); ?>" class="consistency-form-search" placeholder="Enter original to search for&hellip;">
     18        </span>
     19
     20        <span class="consistency-field">
     21            <label for="set">Locale</label>
     22            <?php
     23            $locale_options = [
     24                '' => 'Select a locale',
     25            ];
     26            $locale_options = array_merge( $locale_options, $sets );
     27            echo gp_select(
     28                'set',
     29                $locale_options,
     30                $set,
     31                [
     32                    'class'    => 'consistency-form-locale',
     33                    'required' => 'required',
     34                ]
     35            );
     36            ?>
     37        </span>
     38
     39        <span class="consistency-field">
     40            <label for="project">Project</label>
     41            <?php
     42            $project_options = [
     43                '' => 'All Projects',
     44            ];
     45            $project_options = $project_options + $projects;
     46            echo gp_select(
     47                'project',
     48                $project_options,
     49                $project,
     50                [
     51                    'class' => 'consistency-form-project',
     52                ]
     53            );
     54            ?>
     55        </span>
    2356    </p>
    2457
    25     <p class="consistency-form-filters">
     58    <p>
    2659        <label>
    2760            <input type="checkbox" name="search_case_sensitive" value="1"<?php checked( $search_case_sensitive ); ?>>
     
    3063    </p>
    3164
     65    <p>
     66        <button type="submit" class="consistency-form-submit">Analyze</button>
     67    </p>
    3268</form>
    3369
     
    3874} elseif ( $performed_search && $results ) {
    3975    $translations_unique_count = count( $translations_unique );
    40     if ( 1 === $translations_unique_count ) {
     76    $has_different_translations = $translations_unique_count > 1;
     77    if ( ! $has_different_translations ) {
    4178        echo '<p class="notice">All originals have the same translations</p>';
    4279    } else {
    43         echo '<div class="notice wporg-notice-warning"><p>There are ' . $translations_unique_count . ' different translations. <a id="toggle-translations-unique" href="#show">View</a></p>';
     80        echo '<div id="translations-overview" class="notice wporg-notice-warning"><p>There are ' . $translations_unique_count . ' different translations. <a id="toggle-translations-unique" href="#show">View</a></p>';
    4481        echo '<ul class="translations-unique hidden">';
    4582        foreach ( $translations_unique as $translation ) {
    4683            printf(
    47                 '<li data-id="%s">%s</li>',
    48                 md5( $translation ),
    49                 str_replace( ' ', '<span class="space"> </span>', esc_translation( $translation ) )
     84                '<li>%s <a href="#%s">&darr;</a></li>',
     85                str_replace( ' ', '<span class="space"> </span>', esc_translation( $translation ) ),
     86                esc_attr( sanitize_title( 't-' . $translation ) )
    5087            );
    5188        }
     
    6299        <tbody>
    63100            <?php
     101            $previous_translation = '';
     102
    64103            foreach ( $results as $result ) {
    65104                $project_name = $result->project_name;
     
    76115                        ' <span class="context">%s</span>',
    77116                        esc_translation( $result->original_context )
     117                    );
     118                }
     119
     120                if ( $has_different_translations && $previous_translation !== $result->translation ) {
     121                    $previous_translation = $result->translation;
     122                    printf(
     123                        '<tr id="%s" class="new-translation"><td colspan="2"><strong>%s</strong> <a href="#translations-overview">&uarr;</a></td></tr>',
     124                        esc_attr( sanitize_title( 't-' . $result->translation ) ),
     125                        esc_translation( $result->translation )
    78126                    );
    79127                }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/style.css

    r5031 r6006  
    17501750}
    17511751
    1752 .consistency-form-search,
    1753 .consistency-form-locale {
     1752.consistency-form p {
     1753    margin-bottom: 1em;
     1754}
     1755
     1756.gp-content .consistency-form-search,
     1757.consistency-form-locale,
     1758.consistency-form-project {
    17541759    height: 30px;
    17551760    padding: 3px;
    1756     color: #666;
    17571761    -webkit-box-sizing: border-box;
    17581762    -moz-box-sizing: border-box;
     
    17661770    outline-offset: 0;
    17671771    margin: 0 3px;
     1772    vertical-align: middle;
     1773}
     1774
     1775.consistency-form-search:focus,
     1776.consistency-form-locale:focus,
     1777.consistency-form-project:focus {
     1778    outline: 1px solid #5b9dd9;
     1779    -webkit-box-shadow: 0 0 2px rgba(30,140,190,.8);
     1780    box-shadow: 0 0 2px rgba(30,128,190,.8);
    17681781}
    17691782
     
    17761789}
    17771790
     1791.consistency-form-project {
     1792    width: 120px;
     1793}
     1794
    17781795.consistency-form-submit {
    1779     font-weight: 200;
     1796    background: #0085ba;
     1797    border-color: #0073aa #006799 #006799;
     1798    box-shadow: 0 1px 0 #006799;
     1799    color: #fff;
     1800    height: 30px;
     1801    line-height: 1;
     1802    padding: 0 16px;
     1803    vertical-align: top;
     1804    box-sizing: border-box;
     1805    cursor: pointer;
     1806    display: inline-block;
    17801807    font-size: 15px;
    1781     line-height: 1;
    1782     height: 30px;
    1783     background-color: #21759b;
    1784     background-image: -webkit-gradient(linear, left top, left bottom, from(#2a95c5), to(#21759b));
    1785     background-image: -webkit-linear-gradient(top, #2a95c5, #21759b);
    1786     background-image: linear-gradient(to bottom, #2a95c5, #21759b);
    1787     border: 1px solid #21759b;
    1788     border-bottom-color: #1e6a8d;
    1789     -webkit-box-shadow: inset 0 1px 0 rgba(120, 200, 230, 0.5);
    1790     box-shadow: inset 0 1px 0 rgba(120, 200, 230, 0.5);
     1808}
     1809
     1810.consistency-form-submit:hover,
     1811.consistency-form-submit:focus {
     1812    background: #008ec2;
     1813    border-color: #006799;
     1814    box-shadow: 0 1px 0 #006799;
    17911815    color: #fff;
    1792     text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.3);
    1793     padding: 3px 10px;
    1794     cursor: pointer;
    1795 }
    1796 
    1797 .consistency-form-submit:hover {
    1798     background-color: #278ab7;
    1799     background-image: -webkit-gradient(linear, left top, left bottom, from(#2e9fd2), to(#21759b));
    1800     background-image: -webkit-linear-gradient(top, #2e9fd2, #21759b);
    1801     background-image: linear-gradient(to bottom, #2e9fd2, #21759b);
    1802     border-color: #1b607f;
    1803     -webkit-box-shadow: inset 0 1px 0 rgba(120, 200, 230, 0.6);
    1804     box-shadow: inset 0 1px 0 rgba(120, 200, 230, 0.6);
    1805 }
    1806 
    1807 .consistency-form-filters {
    1808     margin-top: 8px;
    1809 }
    1810 
    1811 .consistency-form-filters label {
    1812     border-right: 1px solid #ccc;
    1813     padding: 0 15px 0 10px;
     1816}
     1817
     1818.consistency-form-submit:focus {
     1819    box-shadow: 0 1px 0 #0073aa, 0 0 2px 1px #33b3db;
     1820}
     1821
     1822.consistency-form-submit:active {
     1823    background: #0073aa;
     1824    border-color: #006799;
     1825    -webkit-box-shadow: inset 0 2px 0 #006799;
     1826    box-shadow: inset 0 2px 0 #006799;
     1827}
     1828
     1829.consistency-field {
    18141830    display: inline-block;
    18151831}
    18161832
    1817 .consistency-form-filters label:last-child {
    1818     border: none;
     1833.consistency-field label {
     1834    display: block;
     1835    margin: 0 3px;
     1836    font-size: 13px;
     1837    text-align: left;
    18191838}
    18201839
     
    18371856}
    18381857
     1858.consistency-table tr.new-translation {
     1859    border-bottom-width: 3px;
     1860}
     1861
    18391862.consistency-table td {
    18401863    padding: 10px 5px 0 0;
    18411864    vertical-align: top;
     1865}
     1866
     1867.consistency-table tr.new-translation td {
     1868    padding: 40px 0 10px;
    18421869}
    18431870
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-consistency.php

    r3013 r6006  
    33namespace WordPressdotorg\GlotPress\Routes\Routes;
    44
     5use GP;
    56use GP_Locales;
    67use GP_Route;
     
    1516    private $cache_group = 'wporg-translate';
    1617
     18    const PROJECTS = [
     19        1   => 'WordPress',
     20        523 => 'Themes',
     21        17  => 'Plugins',
     22        487 => 'Meta',
     23        281 => 'Apps',
     24    ];
     25
    1726    /**
    1827     * Prints a search form and the search results for a consistency view.
     
    2130        $sets = $this->get_translation_sets();
    2231
    23         $search = $set = '';
    24         $search_case_sensitive = true;
     32        $search = $set = $project = '';
     33        $search_case_sensitive = false;
    2534
    2635        if ( ! empty( $_REQUEST['search'] ) ) {
     
    3544        }
    3645
    37         if ( ! empty( $_REQUEST ) && empty( $_REQUEST['search_case_sensitive'] ) ) {
    38             $search_case_sensitive = false;
     46        if ( ! empty( $_REQUEST['search_case_sensitive'] ) ) {
     47            $search_case_sensitive = true;
     48        }
     49
     50        if ( ! empty( $_REQUEST['project'] ) && isset( self::PROJECTS[ $_REQUEST['project'] ] ) ) {
     51            $project = $_REQUEST['project'];
    3952        }
    4053
     
    5366                'set'            => $set,
    5467                'case_sensitive' => $search_case_sensitive,
     68                'project'        => $project,
    5569            ] );
    5670
     
    5872            $translations_unique = array_unique( $translations );
    5973        }
     74
     75        $projects = self::PROJECTS;
    6076
    6177        $this->tmpl( 'consistency', get_defined_vars() );
     
    109125        $slug = $wpdb->prepare( '%s', $slug );
    110126
     127        $project_where = '';
     128        if ( $args['project'] ) {
     129            $project = GP::$project->get( $args['project'] );
     130            $project_where = $wpdb->prepare( 'AND p.path LIKE %s', $wpdb->esc_like( $project->path ) . '/%' );
     131        }
     132
    111133        $results = $wpdb->get_results( "
    112134            SELECT
     
    134156                AND o.status = '+active' AND o.singular {$search}
    135157                AND ts.locale = {$locale} AND ts.slug = {$slug}
     158                {$project_where}
    136159            LIMIT 0, 500
    137160        " );
     
    148171
    149172    public function _sort_callback( $a, $b ) {
    150         return strnatcmp( $a->translation, $b->translation );
     173        return strnatcasecmp( $a->translation, $b->translation );
    151174    }
    152175}
Note: See TracChangeset for help on using the changeset viewer.