diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 8ee28edf3f..e4ac939f4f 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -159,6 +159,8 @@ add_filter( 'wp_sprintf', 'wp_sprintf_l', 10, 2 ); add_filter( 'widget_text', 'balanceTags' ); +add_filter( 'date_i18n', 'wp_maybe_decline_date' ); + // RSS filters add_filter( 'the_title_rss', 'strip_tags' ); add_filter( 'the_title_rss', 'ent2ncr', 8 ); diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 05b5905346..ca00b7c5bd 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -158,6 +158,47 @@ function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) { return $j; } +/** + * Determines if the date should be declined. + * + * If the locale specifies that month names require a genitive case in certain + * formats (like 'j F Y'), the month name will be replaced with a correct form. + * + * @since 4.4.0 + * + * @param string $date Formatted date string. + * @return string The date, declined if locale specifies it. + */ +function wp_maybe_decline_date( $date ) { + global $wp_locale; + + /* translators: If months in your language require a genitive case, + * translate this to 'on'. Do not translate into your own language. + */ + if ( 'on' === _x( 'off', 'decline months names: on or off' ) ) { + // Match a format like 'j F Y' or 'j. F' + if ( @preg_match( '#^\d{1,2}\.? \w+#u', $date ) ) { + $months = $wp_locale->month; + + foreach ( $months as $key => $month ) { + $months[ $key ] = '#' . $month . '#'; + } + + $date = preg_replace( $months, $wp_locale->month_genitive, $date ); + } + } + + // Used for locale-specific rules + $locale = get_locale(); + + if ( 'ca' === $locale ) { + // " de abril| de agost| de octubre..." -> " d'abril| d'agost| d'octubre..." + $date = preg_replace( '# de ([ao])#i', " d'\\1", $date ); + } + + return $date; +} + /** * Convert integer number to format based on the locale. * diff --git a/src/wp-includes/locale.php b/src/wp-includes/locale.php index 2bda4bbf7b..90d969681c 100644 --- a/src/wp-includes/locale.php +++ b/src/wp-includes/locale.php @@ -139,18 +139,32 @@ class WP_Locale { $this->weekday_abbrev[__('Saturday')] = /* translators: three-letter abbreviation of the weekday */ __('Sat'); // The Months - $this->month['01'] = /* translators: month name */ __('January'); - $this->month['02'] = /* translators: month name */ __('February'); - $this->month['03'] = /* translators: month name */ __('March'); - $this->month['04'] = /* translators: month name */ __('April'); - $this->month['05'] = /* translators: month name */ __('May'); - $this->month['06'] = /* translators: month name */ __('June'); - $this->month['07'] = /* translators: month name */ __('July'); - $this->month['08'] = /* translators: month name */ __('August'); - $this->month['09'] = /* translators: month name */ __('September'); - $this->month['10'] = /* translators: month name */ __('October'); - $this->month['11'] = /* translators: month name */ __('November'); - $this->month['12'] = /* translators: month name */ __('December'); + $this->month['01'] = /* translators: month name */ __( 'January' ); + $this->month['02'] = /* translators: month name */ __( 'February' ); + $this->month['03'] = /* translators: month name */ __( 'March' ); + $this->month['04'] = /* translators: month name */ __( 'April' ); + $this->month['05'] = /* translators: month name */ __( 'May' ); + $this->month['06'] = /* translators: month name */ __( 'June' ); + $this->month['07'] = /* translators: month name */ __( 'July' ); + $this->month['08'] = /* translators: month name */ __( 'August' ); + $this->month['09'] = /* translators: month name */ __( 'September' ); + $this->month['10'] = /* translators: month name */ __( 'October' ); + $this->month['11'] = /* translators: month name */ __( 'November' ); + $this->month['12'] = /* translators: month name */ __( 'December' ); + + // The Months, genitive + $this->month_genitive['01'] = /* translators: month name, genitive */ _x( 'January', 'genitive' ); + $this->month_genitive['02'] = /* translators: month name, genitive */ _x( 'February', 'genitive' ); + $this->month_genitive['03'] = /* translators: month name, genitive */ _x( 'March', 'genitive' ); + $this->month_genitive['04'] = /* translators: month name, genitive */ _x( 'April', 'genitive' ); + $this->month_genitive['05'] = /* translators: month name, genitive */ _x( 'May', 'genitive' ); + $this->month_genitive['06'] = /* translators: month name, genitive */ _x( 'June', 'genitive' ); + $this->month_genitive['07'] = /* translators: month name, genitive */ _x( 'July', 'genitive' ); + $this->month_genitive['08'] = /* translators: month name, genitive */ _x( 'August', 'genitive' ); + $this->month_genitive['09'] = /* translators: month name, genitive */ _x( 'September', 'genitive' ); + $this->month_genitive['10'] = /* translators: month name, genitive */ _x( 'October', 'genitive' ); + $this->month_genitive['11'] = /* translators: month name, genitive */ _x( 'November', 'genitive' ); + $this->month_genitive['12'] = /* translators: month name, genitive */ _x( 'December', 'genitive' ); // Abbreviations for each month. $this->month_abbrev[ __( 'January' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Jan', 'January abbreviation' );