WordPress.org

Make WordPress Core

Ticket #13651: comments-number-i18n.2.diff

File comments-number-i18n.2.diff, 14.4 KB (added by SergeyBiryukov, 3 years ago)
  • wp-content/themes/twentyten/loop.php

     
    5353         * 
    5454         * Without further ado, the loop: 
    5555         */ ?> 
    56 <?php while ( have_posts() ) : the_post(); 
     56<?php while ( have_posts() ) : the_post(); ?> 
    5757 
    58 $comment_number_template = _n( '1 Comment', '% Comments', get_comments_number(), 'twentyten' ); 
    59 ?> 
    60  
    6158<?php /* How to display posts of the Gallery format. The gallery category is the old way. */ ?> 
    6259 
    6360        <?php if ( 'gallery' == get_post_format( $post->ID ) || in_category( _x( 'gallery', 'gallery category slug', 'twentyten' ) ) ) : ?> 
     
    9996                                <a href="<?php echo get_term_link( _x( 'gallery', 'gallery category slug', 'twentyten' ), 'category' ); ?>" title="<?php esc_attr_e( 'View posts in the Gallery category', 'twentyten' ); ?>"><?php _e( 'More Galleries', 'twentyten' ); ?></a> 
    10097                                <span class="meta-sep">|</span> 
    10198                        <?php endif; ?> 
    102                                 <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), $comment_number_template, $comment_number_template ); ?></span> 
     99                                <span class="comments-link"><?php comments_number_link( __( 'Leave a comment', 'twentyten' ), _n( '1 Comment', '%s Comments', get_comments_number(), 'twentyten' ) ); ?></span> 
    103100                                <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?> 
    104101                        </div><!-- .entry-utility --> 
    105102                </div><!-- #post-## --> 
     
    122119                        <div class="entry-utility"> 
    123120                                <?php twentyten_posted_on(); ?> 
    124121                                <span class="meta-sep">|</span> 
    125                                 <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), $comment_number_template, $comment_number_template ); ?></span> 
     122                                <span class="comments-link"><?php comments_number_link( __( 'Leave a comment', 'twentyten' ), _n( '1 Comment', '%s Comments', get_comments_number(), 'twentyten' ) ); ?></span> 
    126123                                <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?> 
    127124                        </div><!-- .entry-utility --> 
    128125                </div><!-- #post-## --> 
     
    164161                                        </span> 
    165162                                        <span class="meta-sep">|</span> 
    166163                                <?php endif; ?> 
    167                                 <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), $comment_number_template, $comment_number_template ); ?></span> 
     164                                <span class="comments-link"><?php comments_number_link( __( 'Leave a comment', 'twentyten' ), _n( '1 Comment', '%s Comments', get_comments_number(), 'twentyten' ) ); ?></span> 
    168165                                <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?> 
    169166                        </div><!-- .entry-utility --> 
    170167                </div><!-- #post-## --> 
  • wp-includes/comment-template.php

     
    560560} 
    561561 
    562562/** 
    563  * Display the language string for the number of comments the current post has. 
    564  * 
    565  * @since 0.71 
    566  * @uses apply_filters() Calls the 'comments_number' hook on the output and number of comments respectively. 
    567  * 
    568  * @param string $zero Text for no comments 
    569  * @param string $one Text for one comment 
    570  * @param string $more Text for more than one comment 
    571  * @param string $deprecated Not used. 
     563 * Return the text for the number of comments the current post has. The arguments are the same as those of {@link comments_number_text()} 
     564 *  
     565 * @see comments_number_text() 
    572566 */ 
    573 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) { 
    574         if ( !empty( $deprecated ) ) 
    575                 _deprecated_argument( __FUNCTION__, '1.3' ); 
     567function get_comments_number_text( $zero = null, $plural = null ) { 
     568        $number = get_comments_number(); 
     569        if ( 0 == $number ) { 
     570                $text = is_null( $zero ) ? __( 'No Comments' ) : $zero; 
     571        } else { 
     572                $plural = is_null( $plural )? _n( '1 Comment', '%s Comments', $number ) : $plural; 
     573                $text = sprintf( $plural, number_format_i18n( $number) ); 
     574        } 
     575        return apply_filters( 'get_comments_number_text', $text, $number ); 
     576} 
    576577 
     578/** 
     579 * Display the text for the number of comments the current post has 
     580 *  
     581 * @since 3.1 
     582 * @uses apply_filters() Calls 'comments_number_text' and 'comments_number' (for backwards compatibility) filters on the text and the number of comments 
     583 *  
     584 * @param string $zero the text if there are no comments. Optional. Default is 'No Comments' 
     585 * @param string $plural the result of {@link _n()} or {@link _nx()}, which determines what the text will be depending on different comment numbers. Optional. Default is _n( '1 Comment', '%s Comments', get_comments_number() ) 
     586 */ 
     587function comments_number_text( $zero = null, $plural = null ) { 
    577588        $number = get_comments_number(); 
     589        $after_old_filter = apply_filters( 'comments_number', get_comments_number_text( $zero, $plural ), $number ); 
     590        echo apply_filters( 'comments_number_text', $after_old_filter, $number ); 
     591} 
    578592 
    579         if ( $number > 1 ) 
    580                 $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more); 
    581         elseif ( $number == 0 ) 
    582                 $output = ( false === $zero ) ? __('No Comments') : $zero; 
    583         else // must be one 
    584                 $output = ( false === $one ) ? __('1 Comment') : $one; 
     593/** 
     594 * Return an HTML link to the current post's comments. The arguments are the same as those of {@link comments_number_link()} 
     595 *  
     596 */ 
     597function get_comments_number_link( $zero = null, $plural = null, $disabled = null, $attrs = array() ) { 
     598        global $wpcommentspopupfile, $wpcommentsjavascript; 
     599        $number = get_comments_number(); 
     600         
     601        $disabled = is_null( $disabled )? __( 'Comments Off' ) : $disabled; 
    585602 
    586         echo apply_filters('comments_number', $output, $number); 
     603        if ( 0 == $number && !comments_open() && !pings_open() ) { 
     604                return "<span ".apply_filters( 'get_comments_number_link_attrs', $attrs ).">$disabled</span>"; 
     605        } 
     606 
     607        if ( post_password_required() ) { 
     608                return __( 'Enter your password to view comments.' ); 
     609        } 
     610         
     611        if ( post_password_required() ) { 
     612                echo __('Enter your password to view comments.'); 
     613                return; 
     614        } 
     615 
     616        $attrs['href'] = $number? get_comments_link() : get_permalink() . '#respond'; 
     617        if ( isset( $wpcommentsjavascript ) && $wpcommentsjavascript ) { 
     618                $home = $wpcommentspopupfile? get_option( 'siteurl' ) : home_url(); 
     619                $attrs['href'] = $home . '/' . $wpcommentspopupfile . '?comments_popup=' . get_the_ID(); 
     620                $attrs['onclick'] = 'wpopen(this.href); return false;'; 
     621        } 
     622        $attrs['title'] = sprintf( __('Comment on %s'), get_the_title() ); 
     623        $attrs = apply_filters( 'get_comments_number_link_attrs', $attrs ); 
     624         
     625        $text = get_comments_number_text( $zero, $plural ); 
     626        $html_attrs = wp_html_attributes( $attrs ); 
     627        return "<a $html_attrs>$text</a>"; 
    587628} 
    588629 
    589630/** 
     631 * Display an HTML link to the current post's comments 
     632 *  
     633 * @param string $zero text if there are no comments. Optional. Default is 'No Comments' 
     634 * @param string $plural the result of {@link _n()} or {@link _nx()}, which determines what the text will be depending on different comment numbers 
     635 * @param string $disabled text if comments are disabled. Options. Default is 'Comments Off' 
     636 * @param array $attrs associative array of html attributes and their values (raw, not escaped) 
     637 */ 
     638function comments_number_link( $zero = null, $plural = null, $disabled = null, $attrs = array() ) { 
     639        echo get_comments_number_link( $zero, $plural, $disabled, $attrs ); 
     640} 
     641 
     642/** 
    590643 * Retrieve the text of the current comment. 
    591644 * 
    592645 * @since 1.5.0 
     
    9491002} 
    9501003 
    9511004/** 
    952  * Displays the link to the comments popup window for the current post ID. 
    953  * 
    954  * Is not meant to be displayed on single posts and pages. Should be used on the 
    955  * lists of posts 
    956  * 
    957  * @since 0.71 
    958  * @uses $wpcommentspopupfile 
    959  * @uses $wpcommentsjavascript 
    960  * @uses $post 
    961  * 
    962  * @param string $zero The string to display when no comments 
    963  * @param string $one The string to display when only one comment is available 
    964  * @param string $more The string to display when there are more than one comment 
    965  * @param string $css_class The CSS class to use for comments 
    966  * @param string $none The string to display when comments have been turned off 
    967  * @return null Returns null on single posts and pages. 
    968  */ 
    969 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) { 
    970         global $wpcommentspopupfile, $wpcommentsjavascript; 
    971  
    972         $id = get_the_ID(); 
    973  
    974         if ( false === $zero ) $zero = __( 'No Comments' ); 
    975         if ( false === $one ) $one = __( '1 Comment' ); 
    976         if ( false === $more ) $more = __( '% Comments' ); 
    977         if ( false === $none ) $none = __( 'Comments Off' ); 
    978  
    979         $number = get_comments_number( $id ); 
    980  
    981         if ( 0 == $number && !comments_open() && !pings_open() ) { 
    982                 echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>'; 
    983                 return; 
    984         } 
    985  
    986         if ( post_password_required() ) { 
    987                 echo __('Enter your password to view comments.'); 
    988                 return; 
    989         } 
    990  
    991         echo '<a href="'; 
    992         if ( $wpcommentsjavascript ) { 
    993                 if ( empty( $wpcommentspopupfile ) ) 
    994                         $home = home_url(); 
    995                 else 
    996                         $home = get_option('siteurl'); 
    997                 echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id; 
    998                 echo '" onclick="wpopen(this.href); return false"'; 
    999         } else { // if comments_popup_script() is not in the template, display simple comment link 
    1000                 if ( 0 == $number ) 
    1001                         echo get_permalink() . '#respond'; 
    1002                 else 
    1003                         comments_link(); 
    1004                 echo '"'; 
    1005         } 
    1006  
    1007         if ( !empty( $css_class ) ) { 
    1008                 echo ' class="'.$css_class.'" '; 
    1009         } 
    1010         $title = the_title_attribute( array('echo' => 0 ) ); 
    1011  
    1012         echo apply_filters( 'comments_popup_link_attributes', '' ); 
    1013  
    1014         echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">'; 
    1015         comments_number( $zero, $one, $more ); 
    1016         echo '</a>'; 
    1017 } 
    1018  
    1019 /** 
    10201005 * Retrieve HTML content for reply to comment link. 
    10211006 * 
    10221007 * The default arguments that can be override are 'add_below', 'respond_id', 
  • wp-includes/deprecated.php

     
    25772577        return true; 
    25782578} 
    25792579 
     2580/** 
     2581 * Display the language string for the number of comments the current post has. 
     2582 * 
     2583 * @since 0.71 
     2584 * @uses apply_filters() Calls the 'comments_number' hook on the output and number of comments respectively. 
     2585 * 
     2586 * @param string $zero Text for no comments 
     2587 * @param string $one Text for one comment 
     2588 * @param string $more Text for more than one comment 
     2589 * @param string $deprecated Not used. 
     2590 */ 
     2591function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) { 
     2592        _deprecated_function( __FUNCTION__, '3.1', 'comments_number_text()'  ); 
     2593         
     2594        if ( !empty( $deprecated ) ) 
     2595                _deprecated_argument( __FUNCTION__, '1.3' ); 
     2596 
     2597        $number = get_comments_number(); 
     2598 
     2599        if ( $number > 1 ) 
     2600                $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more); 
     2601        elseif ( $number == 0 ) 
     2602                $output = ( false === $zero ) ? __('No Comments') : $zero; 
     2603        else // must be one 
     2604                $output = ( false === $one ) ? __('1 Comment') : $one; 
     2605 
     2606        echo apply_filters('comments_number', $output, $number); 
     2607} 
     2608 
     2609/** 
     2610 * Displays the link to the comments popup window for the current post ID. 
     2611 * 
     2612 * Is not meant to be displayed on single posts and pages. Should be used on the 
     2613 * lists of posts 
     2614 * 
     2615 * @since 0.71 
     2616 * @uses $wpcommentspopupfile 
     2617 * @uses $wpcommentsjavascript 
     2618 * @uses $post 
     2619 * 
     2620 * @param string $zero The string to display when no comments 
     2621 * @param string $one The string to display when only one comment is available 
     2622 * @param string $more The string to display when there are more than one comment 
     2623 * @param string $css_class The CSS class to use for comments 
     2624 * @param string $none The string to display when comments have been turned off 
     2625 * @return null Returns null on single posts and pages. 
     2626 */ 
     2627function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) { 
     2628        global $wpcommentspopupfile, $wpcommentsjavascript; 
     2629         
     2630        _deprecated_function( __FUNCTION__, '3.1', 'comments_number_link()'  ); 
     2631 
     2632        $id = get_the_ID(); 
     2633 
     2634        if ( false === $zero ) $zero = __( 'No Comments' ); 
     2635        if ( false === $one ) $one = __( '1 Comment' ); 
     2636        if ( false === $more ) $more = __( '% Comments' ); 
     2637        if ( false === $none ) $none = __( 'Comments Off' ); 
     2638 
     2639        $number = get_comments_number( $id ); 
     2640 
     2641        if ( 0 == $number && !comments_open() && !pings_open() ) { 
     2642                echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>'; 
     2643                return; 
     2644        } 
     2645 
     2646        if ( post_password_required() ) { 
     2647                echo __('Enter your password to view comments.'); 
     2648                return; 
     2649        } 
     2650 
     2651        echo '<a href="'; 
     2652        if ( $wpcommentsjavascript ) { 
     2653                if ( empty( $wpcommentspopupfile ) ) 
     2654                        $home = home_url(); 
     2655                else 
     2656                        $home = get_option('siteurl'); 
     2657                echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id; 
     2658                echo '" onclick="wpopen(this.href); return false"'; 
     2659        } else { // if comments_popup_script() is not in the template, display simple comment link 
     2660                if ( 0 == $number ) 
     2661                        echo get_permalink() . '#respond'; 
     2662                else 
     2663                        comments_link(); 
     2664                echo '"'; 
     2665        } 
     2666 
     2667        if ( !empty( $css_class ) ) { 
     2668                echo ' class="'.$css_class.'" '; 
     2669        } 
     2670        $title = the_title_attribute( array('echo' => 0 ) ); 
     2671 
     2672        echo apply_filters( 'comments_popup_link_attributes', '' ); 
     2673 
     2674        echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">'; 
     2675        comments_number( $zero, $one, $more ); 
     2676        echo '</a>'; 
     2677} 
  • wp-includes/formatting.php

     
    28982898 
    28992899} 
    29002900 
    2901 ?> 
     2901/** 
     2902 * Builds an HTML attributes string out of an associattive array 
     2903 *  
     2904 * You don't have to escape the attribute values. 
     2905 *  
     2906 * Example: 
     2907 * <code>wp_html_attributes( array( 'class' => 'post', 'id' => 'post-11' ) )</code> will return <code>'class="post" id="post-11"'</code> 
     2908 *  
     2909 * @param $attr array associative array in the form attribute-name => attribute-value 
     2910 * @return string the attributes suitable for insertion into an HTML tag 
     2911 */ 
     2912function wp_html_attributes( $attrs ) { 
     2913        $attrs = wp_parse_args( $attrs ); 
     2914        $strings = array(); 
     2915        foreach( $attrs as $key => $value ) { 
     2916                $strings[] = $key.'="'.esc_attr( $value ).'"'; 
     2917        } 
     2918        return implode( ' ', $strings ); 
     2919}