mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-05 05:04:31 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@35517 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user