Make WordPress Core

Changeset 45178


Ignore:
Timestamp:
04/12/2019 08:33:48 PM (7 years ago)
Author:
SergeyBiryukov
Message:

Site Health: i18n audit, take 2.

  • Use wp.i18n to translate JavaScript strings.
  • Use _n() for proper plural forms support.

Props TimothyBlynJacobs, ocean90, afercia.
Fixes #46683.

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/site-health.js

    r45176 r45178  
    99jQuery( document ).ready( function( $ ) {
    1010
     11        var __ = wp.i18n.__,
     12                _n = wp.i18n._n,
     13                sprintf = wp.i18n.sprintf;
     14
    1115        var data;
    1216        var clipboard = new ClipboardJS( '.site-health-copy-buttons .copy-button' );
    … …  
    1822                $( '.success', $wrapper ).addClass( 'visible' );
    1923
    20                 wp.a11y.speak( SiteHealth.string.site_info_copied );
     24                wp.a11y.speak( __( 'Site information has been added to your clipboard.' ) );
    2125        } );
    2226
    … …  
    5357                var template = wp.template( 'health-check-issue' ),
    5458                        issueWrapper = $( '#health-check-issues-' + issue.status ),
    55                         issueCounter = $( '.issue-count', issueWrapper );
     59                        heading;
    5660
    5761                SiteHealth.site_status.issues[ issue.status ]++;
    5862
    59                 issueCounter.text( SiteHealth.site_status.issues[ issue.status ] );
     63                var count = SiteHealth.site_status.issues[ issue.status ];
     64
     65                if ( 'critical' === issue.status ) {
     66                        heading = sprintf( _n( '%s Critical issue', '%s Critical issues', count ), '<span class="issue-count">' + count + '</span>' );
     67                } else if ( 'recommended' === issue.status ) {
     68                        heading = sprintf( _n( '%s Recommended improvement', '%s Recommended improvements', count ), '<span class="issue-count">' + count + '</span>' );
     69                } else if ( 'good' === issue.status ) {
     70                        heading = sprintf( _n( '%s Item with no issues detected', '%s Items with no issues detected', count ), '<span class="issue-count">' + count + '</span>' );
     71                }
     72
     73                if ( heading ) {
     74                        $( '> h3', issueWrapper ).html( heading );
     75                }
     76
    6077                $( '.issues', '#health-check-issues-' + issue.status ).append( template( issue ) );
    6178        }
    … …  
    129146                        );
    130147
    131                         wp.a11y.speak( SiteHealth.string.site_health_complete_screen_reader.replace( '%s', val + '%' ) );
     148                        // translators: %s: The percentage score for the tests.
     149                        var text = __( 'All site health tests have finished running. Your site scored %s, and the results are now available on the page.' );
     150                        wp.a11y.speak( sprintf( text, val + '%' ) );
    132151                }
    133152        }
    … …  
    222241                // After 3 seconds announce that we're still waiting for directory sizes.
    223242                var timeout = window.setTimeout( function() {
    224                         wp.a11y.speak( SiteHealth.string.please_wait );
     243                        wp.a11y.speak( __( 'Please wait...' ) );
    225244                }, 3000 );
    226245
    … …  
    249268
    250269                                window.setTimeout( function() {
    251                                         wp.a11y.speak( SiteHealth.string.site_health_complete );
     270                                        wp.a11y.speak( __( 'All site health tests have finished running.' ) );
    252271                                }, delay );
    253272                        } else {
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r45170 r45178  
    4747                $health_check_js_variables = array(
    4848                        'screen'      => $screen->id,
    49                         'string'      => array(
    50                                 'please_wait'                        => __( 'Please wait...' ),
    51                                 'copied'                             => __( 'Copied' ),
    52                                 'running_tests'                      => __( 'Currently being tested...' ),
    53                                 'site_health_complete'               => __( 'All site health tests have finished running.' ),
    54                                 'site_info_show_copy'                => __( 'Show options for copying this information' ),
    55                                 'site_info_hide_copy'                => __( 'Hide options for copying this information' ),
    56                                 // translators: %s: The percentage score for the tests.
    57                                 'site_health_complete_screen_reader' => __( 'All site health tests have finished running. Your site scored %s, and the results are now available on the page.' ),
    58                                 'site_info_copied'                   => __( 'Site information has been added to your clipboard.' ),
    59                         ),
    6049                        'nonce'       => array(
    6150                                'site_status'        => wp_create_nonce( 'health-check-site-status' ),
  • trunk/src/wp-admin/site-health.php

    r45099 r45178  
    9292                <div class="site-health-issues-wrapper" id="health-check-issues-critical">
    9393                        <h3>
    94                                 <span class="issue-count">0</span> <?php _e( 'Critical issues' ); ?>
     94                                <?php printf( _n( '%s Critical issue', '%s Critical issues', 0 ), '<span class="issue-count">0</span>' ); ?>
    9595                        </h3>
    9696
    … …  
    100100                <div class="site-health-issues-wrapper" id="health-check-issues-recommended">
    101101                        <h3>
    102                                 <span class="issue-count">0</span> <?php _e( 'Recommended improvements' ); ?>
     102                                <?php printf( _n( '%s Recommended improvement', '%s Recommended improvements', 0 ), '<span class="issue-count">0</span>' ); ?>
    103103                        </h3>
    104104
  • trunk/src/wp-includes/script-loader.php

    r45168 r45178  
    16911691                );
    16921692
    1693                 $scripts->add( 'site-health', "/wp-admin/js/site-health$suffix.js", array( 'clipboard', 'jquery', 'wp-util', 'wp-a11y' ), false, 1 );
     1693                $scripts->add( 'site-health', "/wp-admin/js/site-health$suffix.js", array( 'clipboard', 'jquery', 'wp-util', 'wp-a11y', 'wp-i18n' ), false, 1 );
    16941694
    16951695                $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y' ), false, 1 );
Note: See TracChangeset for help on using the changeset viewer.