From a26cf7ba6e05e62aa53b1f18dfb252556acdb001 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Tue, 11 Nov 2014 13:24:01 +0000 Subject: [PATCH] Improve localization for `WP_Date_Query` error strings. * Don't create an extra variable for the string when it's only used once. * Avoid using `` HTML tags inside of translatable string. * Improve data types and escaping on sprintfed values. Props dd32. Fixes #25834. git-svn-id: https://develop.svn.wordpress.org/trunk@30300 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/date.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/wp-includes/date.php b/src/wp-includes/date.php index c5896c7f10..de48625280 100644 --- a/src/wp-includes/date.php +++ b/src/wp-includes/date.php @@ -298,10 +298,6 @@ class WP_Date_Query { $valid = $this->validate_date_values( $date_query['after'] ); } - // Message template for the min-max-check. - /* translators: Date query invalid date message: 1: invalid value, 2: type of value, 3: minimum valid value, 4: maximum valid value */ - $min_max_msg = __( 'Invalid value %1$s for %2$s. Excepted value should between %3$d and %4$d.' ); - // Array containing all min-max checks. $min_max_checks = array(); @@ -387,12 +383,14 @@ class WP_Date_Query { $is_between = $date_query[ $key ] >= $check['min'] && $date_query[ $key ] <= $check['max']; if ( ! $is_between ) { + $error = sprintf( - $min_max_msg, - esc_html( $date_query[ $key ] ), - $key, - $check['min'], - $check['max'] + /* translators: Date query invalid date message: 1: invalid value, 2: type of value, 3: minimum valid value, 4: maximum valid value */ + __( 'Invalid value %1$s for %2$s. Expected value should between %3$s and %4$s.' ), + '' . esc_html( $date_query[ $key ] ) . '', + '' . esc_html( $key ) . '', + '' . esc_html( $check['min'] ) . '', + '' . esc_html( $check['max'] ) . '' ); _doing_it_wrong( __CLASS__, $error, '4.1.0' ); @@ -417,10 +415,10 @@ class WP_Date_Query { if ( ! checkdate( $date_query['month'], $date_query['day'], $date_query['year'] ) ) { /* translators: 1: year, 2: month, 3: day of month */ $day_month_year_error_msg = sprintf( - __( 'The following values do not describe a valid date: year %1$s, month %2$s, day %3$s.' ), - esc_html( $date_query['year'] ), - esc_html( $date_query['month'] ), - esc_html( $date_query['day'] ) + __( 'The following values do not describe a valid date: year %1$s, month %2$s, day %3$s.' ), + '' . esc_html( $date_query['year'] ) . '', + '' . esc_html( $date_query['month'] ) . '', + '' . esc_html( $date_query['day'] ) . '' ); $valid = false;