From 0c7a9a4bd65401872ae21c85639106fd5b97159e Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Wed, 29 Jun 2016 12:58:29 +0000 Subject: [PATCH] I18N: Localize the jQuery UI datepicker. This provides some default data for the jQuery UI datepicker. The localized data is already available via `WP_Locale` and is only passed to the datepicker if the script is enqueued. Props clubduece, swissspidy, barryceelen, ocean90. Fixes #29420. Built from https://develop.svn.wordpress.org/trunk@37908 git-svn-id: http://core.svn.wordpress.org/trunk@37849 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/default-filters.php | 2 ++ wp-includes/script-loader.php | 47 +++++++++++++++++++++++++++++++++ wp-includes/version.php | 2 +- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index ddaa5efe24..1b1f01c571 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -404,6 +404,8 @@ add_action( 'set_current_user', 'kses_init' ); // Script Loader 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_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' ); add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' ); diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 2a9f311632..787e050d7c 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -882,7 +882,54 @@ function wp_just_in_time_script_localization() { 'autosaveInterval' => AUTOSAVE_INTERVAL, 'blog_id' => get_current_blog_id(), ) ); +} +/** + * Localizes the jQuery UI datepicker. + * + * @since 4.6.0 + * + * @link http://api.jqueryui.com/datepicker/#options + * @global WP_Locale $wp_locale The WordPress date and time locale object. + */ +function wp_localize_jquery_ui_datepicker() { + global $wp_locale; + + if ( ! wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) { + return; + } + + // Convert the PHP date format into jQuery UI's format. + $datepicker_date_format = str_replace( + array( + 'd', 'j', 'l', 'z', // Day. + 'F', 'M', 'n', 'm', // Month. + 'Y', 'y' // Year. + ), + array( + 'dd', 'd', 'DD', 'o', + 'MM', 'M', 'm', 'mm', + 'yy', 'y' + ), + get_option( 'date_format' ) + ); + + $datepicker_defaults = wp_json_encode( array( + 'closeText' => __( 'Close' ), + 'currentText' => __( 'Today' ), + 'monthNames' => array_values( $wp_locale->month ), + 'monthNamesShort' => array_values( $wp_locale->month_abbrev ), + 'nextText' => __( 'Next' ), + 'prevText' => __( 'Previous' ), + 'dayNames' => array_values( $wp_locale->weekday ), + 'dayNamesShort' => array_values( $wp_locale->weekday_abbrev ), + 'dayNamesMin' => array_values( $wp_locale->weekday_initial ), + 'dateFormat' => $datepicker_date_format, + 'firstDay' => absint( get_option( 'start_of_week' ) ), + 'isRTL' => $wp_locale->is_rtl(), + ) ); + + wp_add_inline_script( 'jquery-ui-datepicker', "jQuery(document).ready(function(jQuery){jQuery.datepicker.setDefaults({$datepicker_defaults});});" ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 4af88bd9d8..70e07ffcd4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.6-alpha-37907'; +$wp_version = '4.6-alpha-37908'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.