Dashboard: Properly localize data for events

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

Props dd32, iandunn.
See #40702.


git-svn-id: https://develop.svn.wordpress.org/trunk@40776 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Konstantin Obenland
2017-05-18 14:33:04 +00:00
parent 043a87446d
commit 0a15718b87
5 changed files with 48 additions and 52 deletions

View File

@@ -1000,6 +1000,46 @@ function wp_localize_jquery_ui_datepicker() {
wp_add_inline_script( 'jquery-ui-datepicker', "jQuery(document).ready(function(jQuery){jQuery.datepicker.setDefaults({$datepicker_defaults});});" );
}
/**
* Localizes community events data that needs to be passed to dashboard.js.
*
* @since 4.8.0
*/
function wp_localize_community_events() {
if ( ! wp_script_is( 'dashboard' ) ) {
return;
}
require_once( ABSPATH . 'wp-admin/includes/class-wp-community-events.php' );
$user_id = get_current_user_id();
$user_location = get_user_option( 'community-events-location', $user_id );
$events_client = new WP_Community_Events( $user_id, $user_location );
wp_localize_script( 'dashboard', 'communityEventsData', array(
'nonce' => wp_create_nonce( 'community_events' ),
'cache' => $events_client->get_cached_events(),
'l10n' => array(
'enter_closest_city' => __( 'Enter your closest city to find nearby events.' ),
'error_occurred_please_try_again' => __( 'An error occurred. Please try again.' ),
/*
* These specific examples were chosen to highlight the fact that a
* state is not needed, even for cities whose name is not unique.
* It would be too cumbersome to include that in the instructions
* to the user, so it's left as an implication.
*/
/* 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. */
'could_not_locate_city' => __( 'We couldn’t locate %s. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ),
// This one is only used with wp.a11y.speak(), so it can/should be more brief.
/* translators: %s is the name of a city. */
'city_updated' => __( 'City updated. Listing events near %s.' ),
)
) );
}
/**
* Administration Screen CSS for changing the styles.
*