From d9b4f1e50b729376d744f574f842a8b253bca5fb Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 6 Jul 2016 14:46:32 +0000 Subject: [PATCH] I18N: Introduce an on/off switch for locales where comment number needs to be declined. When enabled, the switch would override the theme's pseudo-plural `'% Comments'` string with a correct form of `_n( '%s Comment', '%s Comments', $number )`. Historically, `comments_popup_link()` and `get_comments_number_text()` did not support plural forms and used a pseudo-plural style instead, so some locales were forced to come up with workarounds to display the number of comments in their language correctly. This change should make those functions more i18n-friendly. Fixes #13651. Built from https://develop.svn.wordpress.org/trunk@37987 git-svn-id: http://core.svn.wordpress.org/trunk@37928 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment-template.php | 21 +++++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index 75ed045cd3..04b443f732 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -893,6 +893,27 @@ function get_comments_number_text( $zero = false, $one = false, $more = false ) $output = sprintf( _n( '%s Comment', '%s Comments', $number ), number_format_i18n( $number ) ); } else { // % Comments + /* translators: If comment number in your language requires declension, + * translate this to 'on'. Do not translate into your own language. + */ + if ( 'on' === _x( 'off', 'Comment number declension: on or off' ) ) { + $text = preg_replace( '#.+?#', '', $more ); + $text = preg_replace( '/&.+?;/', '', $text ); // Kill entities + $text = trim( strip_tags( $text ), '% ' ); + + // Replace '% Comments' with a proper plural form + if ( $text && ! preg_match( '/[0-9]+/', $text ) && false !== strpos( $more, '%' ) ) { + /* translators: %s: number of comments */ + $new_text = _n( '%s Comment', '%s Comments', $number ); + $new_text = trim( sprintf( $new_text, '' ) ); + + $more = str_replace( $text, $new_text, $more ); + if ( false === strpos( $more, '%' ) ) { + $more = '% ' . $more; + } + } + } + $output = str_replace( '%', number_format_i18n( $number ), $more ); } } elseif ( $number == 0 ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index d5121eabd0..a40d02afd3 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.6-beta1-37986'; +$wp_version = '4.6-beta1-37987'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.