mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-04 12:44:31 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@37987 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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( '#<span class="screen-reader-text">.+?</span>#', '', $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 ) {
|
||||
|
||||
Reference in New Issue
Block a user