Index: src/wp-admin/includes/dashboard.php
===================================================================
--- src/wp-admin/includes/dashboard.php	(revision 40773)
+++ src/wp-admin/includes/dashboard.php	(working copy)
@@ -130,46 +130,6 @@
 }
 
 /**
- * Gets the community events data that needs to be passed to dashboard.js.
- *
- * @since 4.8.0
- *
- * @return array The script data.
- */
-function wp_get_community_events_script_data() {
-	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 );
-
-	$script_data = 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 occured. 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.' ),
-		)
-	);
-
-	return $script_data;
-}
-
-/**
  * Adds a new dashboard widget.
  *
  * @since 2.7.0
@@ -1170,24 +1130,22 @@
  * @since 4.8.0
  */
 function wp_print_community_events_markup() {
-	$script_data = wp_get_community_events_script_data();
-
 	?>
 
 	<div class="community-events-errors notice notice-error inline hide-if-js">
 		<p class="hide-if-js">
-			<?php _e( 'This widget requires JavaScript.'); ?>
+			<?php _e( 'This widget requires JavaScript.' ); ?>
 		</p>
 
 		<p class="community-events-error-occurred" aria-hidden="true">
-			<?php echo $script_data['l10n']['error_occurred_please_try_again']; ?>
+			<?php _e( 'An error occurred. Please try again.' ); ?>
 		</p>
 
 		<p class="community-events-could-not-locate" aria-hidden="true"></p>
 	</div>
 
 	<div class="community-events-loading hide-if-no-js">
-		<?php _e( 'Loading&hellip;'); ?>
+		<?php _e( 'Loading&hellip;' ); ?>
 	</div>
 
 	<?php
@@ -1201,7 +1159,7 @@
 			<p>
 				<span id="community-events-location-message"></span>
 
-				<button class="button-link community-events-toggle-location" aria-label="<?php _e( 'Edit city'); ?>" aria-expanded="false">
+				<button class="button-link community-events-toggle-location" aria-label="<?php esc_attr_e( 'Edit city' ); ?>" aria-expanded="false">
 					<span class="dashicons dashicons-edit"></span>
 				</button>
 			</p>
@@ -1211,7 +1169,7 @@
 					<?php _e( 'City:' ); ?>
 				</label>
 				<?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. */ ?>
-				<input id="community-events-location" class="regular-text" type="text" name="community-events-location" placeholder="<?php _e( 'Cincinnati' ); ?>" />
+				<input id="community-events-location" class="regular-text" type="text" name="community-events-location" placeholder="<?php esc_attr_e( 'Cincinnati' ); ?>" />
 
 				<?php submit_button( __( 'Submit' ), 'secondary', 'community-events-submit', false ); ?>
 
@@ -1235,8 +1193,6 @@
  * @since 4.8.0
  */
 function wp_print_community_events_templates() {
-	$script_data = wp_get_community_events_script_data();
-
 	?>
 
 	<script id="tmpl-community-events-attend-event-near" type="text/template">
@@ -1249,7 +1205,8 @@
 
 	<script id="tmpl-community-events-could-not-locate" type="text/template">
 		<?php printf(
-			$script_data['l10n']['could_not_locate_city'],
+			/* 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. */
+			__( 'We couldn&#8217;t locate %s. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ),
 			'<em>{{data.unknownCity}}</em>'
 		); ?>
 	</script>
Index: src/wp-admin/index.php
===================================================================
--- src/wp-admin/index.php	(revision 40773)
+++ src/wp-admin/index.php	(working copy)
@@ -15,7 +15,6 @@
 wp_dashboard_setup();
 
 wp_enqueue_script( 'dashboard' );
-wp_localize_script( 'dashboard', 'communityEventsData', wp_get_community_events_script_data() );
 
 if ( current_user_can( 'edit_theme_options' ) )
 	wp_enqueue_script( 'customize-loader' );
Index: src/wp-admin/network/index.php
===================================================================
--- src/wp-admin/network/index.php	(revision 40773)
+++ src/wp-admin/network/index.php	(working copy)
@@ -54,7 +54,6 @@
 wp_dashboard_setup();
 
 wp_enqueue_script( 'dashboard' );
-wp_localize_script( 'dashboard', 'communityEventsData', wp_get_community_events_script_data() );
 wp_enqueue_script( 'plugin-install' );
 add_thickbox();
 
Index: src/wp-includes/default-filters.php
===================================================================
--- src/wp-includes/default-filters.php	(revision 40773)
+++ src/wp-includes/default-filters.php	(working copy)
@@ -434,6 +434,7 @@
 add_action( 'wp_default_scripts', 'wp_default_scripts' );
 add_action( 'wp_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 );
 add_action( 'admin_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 );
+add_action( 'admin_print_scripts-index.php', 'wp_localize_community_events' );
 add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' );
 add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );
 add_filter( 'customize_controls_print_styles', 'wp_resource_hints', 1 );
Index: src/wp-includes/script-loader.php
===================================================================
--- src/wp-includes/script-loader.php	(revision 40773)
+++ src/wp-includes/script-loader.php	(working copy)
@@ -1001,6 +1001,44 @@
 }
 
 /**
+ * Gets the community events data that needs to be passed to dashboard.js.
+ *
+ * @since 4.8.0
+ *
+ * @return array The script data.
+ */
+function wp_localize_community_events() {
+	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&#8217;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.
  *
  * If installing the 'wp-admin/' directory will be replaced with './'.
