Make WordPress Core


Ignore:
Timestamp:
07/06/2016 02:45:55 PM (8 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment-template.php

    r37985 r37987  
    894894        } else {
    895895            // % Comments
     896            /* translators: If comment number in your language requires declension,
     897             * translate this to 'on'. Do not translate into your own language.
     898             */
     899            if ( 'on' === _x( 'off', 'Comment number declension: on or off' ) ) {
     900                $text = preg_replace( '#<span class="screen-reader-text">.+?</span>#', '', $more );
     901                $text = preg_replace( '/&.+?;/', '', $text ); // Kill entities
     902                $text = trim( strip_tags( $text ), '% ' );
     903
     904                // Replace '% Comments' with a proper plural form
     905                if ( $text && ! preg_match( '/[0-9]+/', $text ) && false !== strpos( $more, '%' ) ) {
     906                    /* translators: %s: number of comments */
     907                    $new_text = _n( '%s Comment', '%s Comments', $number );
     908                    $new_text = trim( sprintf( $new_text, '' ) );
     909
     910                    $more = str_replace( $text, $new_text, $more );
     911                    if ( false === strpos( $more, '%' ) ) {
     912                        $more = '% ' . $more;
     913                    }
     914                }
     915            }
     916
    896917            $output = str_replace( '%', number_format_i18n( $number ), $more );
    897918        }
Note: See TracChangeset for help on using the changeset viewer.