Make WordPress Core

Changeset 40776


Ignore:
Timestamp:
05/18/2017 02:33:04 PM (7 years ago)
Author:
obenland
Message:

Dashboard: Properly localize data for events

Moves localization to script-loader and removes dependency for two strings.

Props dd32, iandunn.
See #40702.

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/dashboard.php

    r40651 r40776  
    128128    /** This action is documented in wp-admin/edit-form-advanced.php */
    129129    do_action( 'do_meta_boxes', $screen->id, 'side', '' );
    130 }
    131 
    132 /**
    133  * Gets the community events data that needs to be passed to dashboard.js.
    134  *
    135  * @since 4.8.0
    136  *
    137  * @return array The script data.
    138  */
    139 function wp_get_community_events_script_data() {
    140     require_once( ABSPATH . 'wp-admin/includes/class-wp-community-events.php' );
    141 
    142     $user_id       = get_current_user_id();
    143     $user_location = get_user_option( 'community-events-location', $user_id );
    144     $events_client = new WP_Community_Events( $user_id, $user_location );
    145 
    146     $script_data = array(
    147         'nonce' => wp_create_nonce( 'community_events' ),
    148         'cache' => $events_client->get_cached_events(),
    149 
    150         'l10n' => array(
    151             'enter_closest_city' => __( 'Enter your closest city to find nearby events.' ),
    152             'error_occurred_please_try_again' => __( 'An error occured. Please try again.' ),
    153 
    154             /*
    155              * These specific examples were chosen to highlight the fact that a
    156              * state is not needed, even for cities whose name is not unique.
    157              * It would be too cumbersome to include that in the instructions
    158              * to the user, so it's left as an implication.
    159              */
    160             /* translators: %s is the name of the city we couldn't locate. Replace the examples with cities in your locale, but test that they match the expected location before including them. Use endonyms (native locale names) whenever possible. */
    161             'could_not_locate_city' => __( "We couldn't locate %s. Please try another nearby city. For example: Kansas City; Springfield; Portland." ),
    162 
    163             // This one is only used with wp.a11y.speak(), so it can/should be more brief.
    164             /* translators: %s is the name of a city. */
    165             'city_updated' => __( 'City updated. Listing events near %s.' ),
    166         )
    167     );
    168 
    169     return $script_data;
    170130}
    171131
     
    11711131 */
    11721132function wp_print_community_events_markup() {
    1173     $script_data = wp_get_community_events_script_data();
    1174 
    11751133    ?>
    11761134
    11771135    <div class="community-events-errors notice notice-error inline hide-if-js">
    11781136        <p class="hide-if-js">
    1179             <?php _e( 'This widget requires JavaScript.'); ?>
     1137            <?php _e( 'This widget requires JavaScript.' ); ?>
    11801138        </p>
    11811139
    11821140        <p class="community-events-error-occurred" aria-hidden="true">
    1183             <?php echo $script_data['l10n']['error_occurred_please_try_again']; ?>
     1141            <?php _e( 'An error occurred. Please try again.' ); ?>
    11841142        </p>
    11851143
     
    11881146
    11891147    <div class="community-events-loading hide-if-no-js">
    1190         <?php _e( 'Loading&hellip;'); ?>
     1148        <?php _e( 'Loading&hellip;' ); ?>
    11911149    </div>
    11921150
     
    12021160                <span id="community-events-location-message"></span>
    12031161
    1204                 <button class="button-link community-events-toggle-location" aria-label="<?php _e( 'Edit city'); ?>" aria-expanded="false">
     1162                <button class="button-link community-events-toggle-location" aria-label="<?php esc_attr_e( 'Edit city' ); ?>" aria-expanded="false">
    12051163                    <span class="dashicons dashicons-edit"></span>
    12061164                </button>
     
    12121170                </label>
    12131171                <?php /* translators: Replace with the name of a city in your locale that shows events. Use only the city name itself, without any region or country. Use the endonym instead of the English name. */ ?>
    1214                 <input id="community-events-location" class="regular-text" type="text" name="community-events-location" placeholder="<?php _e( 'Cincinnati' ); ?>" />
     1172                <input id="community-events-location" class="regular-text" type="text" name="community-events-location" placeholder="<?php esc_attr_e( 'Cincinnati' ); ?>" />
    12151173
    12161174                <?php submit_button( __( 'Submit' ), 'secondary', 'community-events-submit', false ); ?>
     
    12361194 */
    12371195function wp_print_community_events_templates() {
    1238     $script_data = wp_get_community_events_script_data();
    1239 
    12401196    ?>
    12411197
     
    12501206    <script id="tmpl-community-events-could-not-locate" type="text/template">
    12511207        <?php printf(
    1252             $script_data['l10n']['could_not_locate_city'],
     1208            /* translators: %s is the name of the city we couldn't locate. Replace the examples with cities in your locale, but test that they match the expected location before including them. Use endonyms (native locale names) whenever possible. */
     1209            __( 'We couldn&#8217;t locate %s. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ),
    12531210            '<em>{{data.unknownCity}}</em>'
    12541211        ); ?>
  • trunk/src/wp-admin/index.php

    r40607 r40776  
    1616
    1717wp_enqueue_script( 'dashboard' );
    18 wp_localize_script( 'dashboard', 'communityEventsData', wp_get_community_events_script_data() );
    1918
    2019if ( current_user_can( 'edit_theme_options' ) )
  • trunk/src/wp-admin/network/index.php

    r40607 r40776  
    5555
    5656wp_enqueue_script( 'dashboard' );
    57 wp_localize_script( 'dashboard', 'communityEventsData', wp_get_community_events_script_data() );
    5857wp_enqueue_script( 'plugin-install' );
    5958add_thickbox();
  • trunk/src/wp-includes/default-filters.php

    r40676 r40776  
    435435add_action( 'wp_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 );
    436436add_action( 'admin_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 );
     437add_action( 'admin_print_scripts-index.php', 'wp_localize_community_events' );
    437438add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' );
    438439add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );
  • trunk/src/wp-includes/script-loader.php

    r40775 r40776  
    10021002
    10031003/**
     1004 * Localizes community events data that needs to be passed to dashboard.js.
     1005 *
     1006 * @since 4.8.0
     1007 */
     1008function wp_localize_community_events() {
     1009    if ( ! wp_script_is( 'dashboard' ) ) {
     1010        return;
     1011    }
     1012
     1013    require_once( ABSPATH . 'wp-admin/includes/class-wp-community-events.php' );
     1014
     1015    $user_id       = get_current_user_id();
     1016    $user_location = get_user_option( 'community-events-location', $user_id );
     1017    $events_client = new WP_Community_Events( $user_id, $user_location );
     1018
     1019    wp_localize_script( 'dashboard', 'communityEventsData', array(
     1020        'nonce' => wp_create_nonce( 'community_events' ),
     1021        'cache' => $events_client->get_cached_events(),
     1022
     1023        'l10n' => array(
     1024            'enter_closest_city' => __( 'Enter your closest city to find nearby events.' ),
     1025            'error_occurred_please_try_again' => __( 'An error occurred. Please try again.' ),
     1026
     1027            /*
     1028             * These specific examples were chosen to highlight the fact that a
     1029             * state is not needed, even for cities whose name is not unique.
     1030             * It would be too cumbersome to include that in the instructions
     1031             * to the user, so it's left as an implication.
     1032             */
     1033            /* translators: %s is the name of the city we couldn't locate. Replace the examples with cities in your locale, but test that they match the expected location before including them. Use endonyms (native locale names) whenever possible. */
     1034            'could_not_locate_city' => __( 'We couldn&#8217;t locate %s. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ),
     1035
     1036            // This one is only used with wp.a11y.speak(), so it can/should be more brief.
     1037            /* translators: %s is the name of a city. */
     1038            'city_updated' => __( 'City updated. Listing events near %s.' ),
     1039        )
     1040    ) );
     1041}
     1042
     1043/**
    10041044 * Administration Screen CSS for changing the styles.
    10051045 *
Note: See TracChangeset for help on using the changeset viewer.