mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-16 11:35:48 +00:00
Introduce wp_maybe_decline_date()
for languages where certain date formats need to be declined, and hook it to the date_i18n
filter.
If the locale specifies that month names require a genitive case in certain formats like `'j F Y'` or `'j. F'`, the month name will be replaced with a correct form. Fixes #11226. Built from https://develop.svn.wordpress.org/trunk@35517 git-svn-id: http://core.svn.wordpress.org/trunk@35481 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c443d45708
commit
5d87e7d2b8
@ -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 );
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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' );
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.4-beta2-35516';
|
||||
$wp_version = '4.4-beta2-35517';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
x
Reference in New Issue
Block a user