WordPress.org

Make WordPress Core

Ticket #13651: comments-number-i18n.diff

File comments-number-i18n.diff, 17.1 KB (added by nbachiyski, 3 years ago)
  • wp-includes/l10n.php

     
    272272 * @since 2.5 
    273273 * @param string $single Single form to be i18ned 
    274274 * @param string $plural Plural form to be i18ned 
    275  * @return array array($single, $plural) 
     275 * @param string $domain Gettext domain. Optional. If not present, the domain passed to {@link translate_nooped_plural()} will be used. 
     276 * @return array array('single' => $single, 'plural' => $plural, ...) 
    276277 */ 
    277 function _n_noop( $singular, $plural ) { 
    278         return array( 0 => $singular, 1 => $plural, 'singular' => $singular, 'plural' => $plural, 'context' => null ); 
     278function _n_noop( $singular, $plural, $domain = null ) { 
     279        return array( 'singular' => $singular, 'plural' => $plural, 'context' => null, 'domain' => $domain ); 
    279280} 
    280281 
    281282/** 
     
    283284 * 
    284285 * @see _n_noop() 
    285286 */ 
    286 function _nx_noop( $singular, $plural, $context ) { 
    287         return array( 0 => $singular, 1 => $plural, 2 => $context, 'singular' => $singular, 'plural' => $plural, 'context' => $context ); 
     287function _nx_noop( $singular, $plural, $context, $domain = null ) { 
     288        return array( 'singular' => $singular, 'plural' => $plural, 'context' => $context, 'domain' => $domain ); 
    288289} 
    289290 
    290291/** 
     
    293294 * @since 3.1 
    294295 * @param array $nooped_plural array with singular, plural and context keys, usually the result of _n_noop() or _nx_noop() 
    295296 * @param int $count number of objects 
    296  * @param string $domain Optional. The domain identifier the text should be retrieved in 
     297 * @param string $domain Optional. The domain identifier the text should be retrieved in. Used only in case $nooped_plural doesn't contain a domain 
    297298 */ 
    298299function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) { 
     300        $domain = is_null( $nooped_plural['domain'] )? $domain : $nooped_plural['domain']; 
    299301        if ( $nooped_plural['context'] ) 
    300302                return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain ); 
    301303        else 
  • 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, $nooped_plural = null ) { 
     568        $number = get_comments_number(); 
     569        if ( 0 == $number ) { 
     570                $text = is_null( $zero )? __( 'No Comments' ) : $zero; 
     571        } else { 
     572                $nooped_plural = is_null( $nooped_plural )? _n_noop( '1 Comment', '%s Comments' ) : $nooped_plural; 
     573                $format = translate_nooped_plural( $nooped_plural, $number ); 
     574                $text = sprintf( $format, number_format_i18n( $number) ); 
     575        } 
     576        return apply_filters( 'get_comments_number_text', $text, $number ); 
     577} 
    576578 
     579/** 
     580 * Display the text for the number of comments the current post has 
     581 *  
     582 * @since 3.1 
     583 * @uses apply_filters() Calls 'comments_number_text' and 'comments_number' (for backwards compatibility) filters on the text and the number of comments 
     584 *  
     585 * @param string $zero the text if there are no comments. Optional. Default is 'No Comments' 
     586 * @param string $nooped_plural the result of {@link _n_noop()} or {@link _nx_noop()}, which determines what the text will be depending on different comment numbers. Optional. Default is _n_noop( '1 Comment', '%s Comments' ) 
     587 */ 
     588function comments_number_text( $zero = null, $nooped_plural = null ) { 
    577589        $number = get_comments_number(); 
     590        $after_old_filter = apply_filters( 'comments_number', get_comments_number_text( $zero, $nooped_plural ), $number ); 
     591        echo apply_filters( 'comments_number_text', $after_old_filter, $number ); 
     592} 
    578593 
    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; 
     594/** 
     595 * Return an HTML link to the current post's comments. The arguments are the same as those of {@link comments_number_link()} 
     596 *  
     597 */ 
     598function get_comments_number_link( $zero = null, $nooped_plural = null, $disabled = null, $attrs = array() ) { 
     599        global $wpcommentspopupfile, $wpcommentsjavascript; 
     600        $number = get_comments_number(); 
     601         
     602        $disabled = is_null( $disabled )? __( 'Comments Off' ) : $disabled; 
    585603 
    586         echo apply_filters('comments_number', $output, $number); 
     604        if ( 0 == $number && !comments_open() && !pings_open() ) { 
     605                return "<span ".apply_filters( 'get_comments_number_link_attrs', $attrs ).">$disabled</span>"; 
     606        } 
     607 
     608        if ( post_password_required() ) { 
     609                return __( 'Enter your password to view comments.' ); 
     610        } 
     611         
     612        if ( post_password_required() ) { 
     613                echo __('Enter your password to view comments.'); 
     614                return; 
     615        } 
     616 
     617        $attrs['href'] = $number? get_comments_link() : get_permalink() . '#respond'; 
     618        if ( isset( $wpcommentsjavascript ) && $wpcommentsjavascript ) { 
     619                $home = $wpcommentspopupfile? get_option( 'siteurl' ) : home_url(); 
     620                $attrs['href'] = $home . '/' . $wpcommentspopupfile . '?comments_popup=' . get_the_ID(); 
     621                $attrs['onclick'] = 'wpopen(this.href); return false;'; 
     622        } 
     623        $attrs['title'] = sprintf( __('Comment on %s'), get_the_title() ); 
     624        $attrs = apply_filters( 'get_comments_number_link_attrs', $attrs ); 
     625         
     626        $text = get_comments_number_text( $zero, $nooped_plural ); 
     627        $html_attrs = wp_html_attributes( $attrs ); 
     628        return "<a $html_attrs>$text</a>"; 
    587629} 
    588630 
    589631/** 
     632 * Display an HTML link to the current post's comments 
     633 *  
     634 * @param string $zero text if there are no comments. Optional. Default is 'No Comments' 
     635 * @param string $nooped_plural the result of {@link _n_noop()} or {@link _nx_noop()}, which determines what the text will be depending on different comment numbers 
     636 * @param string $disabled text if comments are disabled. Options. Default is 'Comments Off' 
     637 * @param array $attrs associative array of html attributes and their values (raw, not escaped) 
     638 */ 
     639function comments_number_link( $zero = null, $nooped_plural = null, $disabled = null, $attrs = array() ) { 
     640        echo get_comments_number_link( $zero, $nooped_plural, $disabled, $attrs ); 
     641} 
     642 
     643/** 
    590644 * Retrieve the text of the current comment. 
    591645 * 
    592646 * @since 1.5.0 
     
    9491003} 
    9501004 
    9511005/** 
    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 /** 
    10201006 * Retrieve HTML content for reply to comment link. 
    10211007 * 
    10221008 * The default arguments that can be override are 'add_below', 'respond_id', 
  • wp-includes/formatting.php

     
    28912891 
    28922892} 
    28932893 
    2894 ?> 
     2894/** 
     2895 * Builds an HTML attributes string out of an associattive array 
     2896 *  
     2897 * You don't have to escape the attribute values. 
     2898 *  
     2899 * Example: 
     2900 * <code>wp_html_attributes( array( 'class' => 'post', 'id' => 'post-11' ) )</code> will return <code>'class="post" id="post-11"'</code> 
     2901 *  
     2902 * @param $attr array associative array in the form attribute-name => attribute-value 
     2903 * @return string the attributes suitable for insertion into an HTML tag 
     2904 */ 
     2905function wp_html_attributes( $attrs ) { 
     2906        $attrs = wp_parse_args( $attrs ); 
     2907        $strings = array(); 
     2908        foreach( $attrs as $key => $value ) { 
     2909                $strings[] = $key.'="'.esc_attr( $value ).'"'; 
     2910        } 
     2911        return implode( ' ', $strings ); 
     2912} 
     2913 No newline at end of file 
  • 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} 
     2678 No newline at end of file 
  • 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( '% Comment', '% Comments', get_comments_number(), 'twentyten' ); 
    59 ?> 
    60  
    6158<?php /* How to display posts in the Gallery category. */ ?> 
    6259 
    6360        <?php if ( in_category( _x( 'gallery', 'gallery category slug', 'twentyten' ) ) || 'gallery' == get_post_format( $post->ID ) ) : ?> 
     
    9693                                <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> 
    9794                                <span class="meta-sep">|</span> 
    9895                        <?php endif; ?> 
    99                                 <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), $comment_number_template, $comment_number_template ); ?></span> 
     96                                <span class="comments-link"><?php comments_number_link( __( 'Leave a comment', 'twentyten' ), _n_noop( '1 Comment', '%s Comments', 'twentyten' ) ); ?></span> 
    10097                                <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?> 
    10198                        </div><!-- .entry-utility --> 
    10299                </div><!-- #post-## --> 
     
    119116                        <div class="entry-utility"> 
    120117                                <?php twentyten_posted_on(); ?> 
    121118                                <span class="meta-sep">|</span> 
    122                                 <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), $comment_number_template, $comment_number_template ); ?></span> 
     119                                <span class="comments-link"><?php comments_number_link( __( 'Leave a comment', 'twentyten' ), _n_noop( '1 Comment', '%s Comments', 'twentyten' ) ); ?></span> 
    123120                                <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?> 
    124121                        </div><!-- .entry-utility --> 
    125122                </div><!-- #post-## --> 
     
    128125 
    129126        <?php else : ?> 
    130127                <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 
    131                         <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2> 
     128                        <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2> 
    132129 
    133130                        <div class="entry-meta"> 
    134131                                <?php twentyten_posted_on(); ?> 
     
    161158                                        </span> 
    162159                                        <span class="meta-sep">|</span> 
    163160                                <?php endif; ?> 
    164                                 <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), $comment_number_template, $comment_number_template ); ?></span> 
     161                                <span class="comments-link"><?php comments_number_link( __( 'Leave a comment', 'twentyten' ), _n_noop( '1 Comment', '%s Comments', 'twentyten' ) ); ?></span> 
    165162                                <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?> 
    166163                        </div><!-- .entry-utility --> 
    167164                </div><!-- #post-## -->