Ticket #13651: comments-number-i18n.diff
File comments-number-i18n.diff, 17.1 KB (added by , 12 years ago) |
---|
-
wp-includes/l10n.php
272 272 * @since 2.5 273 273 * @param string $single Single form to be i18ned 274 274 * @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, ...) 276 277 */ 277 function _n_noop( $singular, $plural ) {278 return array( 0 => $singular, 1 => $plural, 'singular' => $singular, 'plural' => $plural, 'context' => null);278 function _n_noop( $singular, $plural, $domain = null ) { 279 return array( 'singular' => $singular, 'plural' => $plural, 'context' => null, 'domain' => $domain ); 279 280 } 280 281 281 282 /** … … 283 284 * 284 285 * @see _n_noop() 285 286 */ 286 function _nx_noop( $singular, $plural, $context ) {287 return array( 0 => $singular, 1 => $plural, 2 => $context, 'singular' => $singular, 'plural' => $plural, 'context' => $context);287 function _nx_noop( $singular, $plural, $context, $domain = null ) { 288 return array( 'singular' => $singular, 'plural' => $plural, 'context' => $context, 'domain' => $domain ); 288 289 } 289 290 290 291 /** … … 293 294 * @since 3.1 294 295 * @param array $nooped_plural array with singular, plural and context keys, usually the result of _n_noop() or _nx_noop() 295 296 * @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 297 298 */ 298 299 function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) { 300 $domain = is_null( $nooped_plural['domain'] )? $domain : $nooped_plural['domain']; 299 301 if ( $nooped_plural['context'] ) 300 302 return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain ); 301 303 else -
wp-includes/comment-template.php
560 560 } 561 561 562 562 /** 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() 572 566 */ 573 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) { 574 if ( !empty( $deprecated ) ) 575 _deprecated_argument( __FUNCTION__, '1.3' ); 567 function 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 } 576 578 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 */ 588 function comments_number_text( $zero = null, $nooped_plural = null ) { 577 589 $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 } 578 593 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 */ 598 function 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; 585 603 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>"; 587 629 } 588 630 589 631 /** 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 */ 639 function 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 /** 590 644 * Retrieve the text of the current comment. 591 645 * 592 646 * @since 1.5.0 … … 949 1003 } 950 1004 951 1005 /** 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 the955 * lists of posts956 *957 * @since 0.71958 * @uses $wpcommentspopupfile959 * @uses $wpcommentsjavascript960 * @uses $post961 *962 * @param string $zero The string to display when no comments963 * @param string $one The string to display when only one comment is available964 * @param string $more The string to display when there are more than one comment965 * @param string $css_class The CSS class to use for comments966 * @param string $none The string to display when comments have been turned off967 * @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 else996 $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 link1000 if ( 0 == $number )1001 echo get_permalink() . '#respond';1002 else1003 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 /**1020 1006 * Retrieve HTML content for reply to comment link. 1021 1007 * 1022 1008 * The default arguments that can be override are 'add_below', 'respond_id', -
wp-includes/formatting.php
2891 2891 2892 2892 } 2893 2893 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 */ 2905 function 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
2577 2577 return true; 2578 2578 } 2579 2579 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 */ 2591 function 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 */ 2627 function 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
53 53 * 54 54 * Without further ado, the loop: 55 55 */ ?> 56 <?php while ( have_posts() ) : the_post(); 56 <?php while ( have_posts() ) : the_post(); ?> 57 57 58 $comment_number_template = _n( '% Comment', '% Comments', get_comments_number(), 'twentyten' );59 ?>60 61 58 <?php /* How to display posts in the Gallery category. */ ?> 62 59 63 60 <?php if ( in_category( _x( 'gallery', 'gallery category slug', 'twentyten' ) ) || 'gallery' == get_post_format( $post->ID ) ) : ?> … … 96 93 <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> 97 94 <span class="meta-sep">|</span> 98 95 <?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> 100 97 <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?> 101 98 </div><!-- .entry-utility --> 102 99 </div><!-- #post-## --> … … 119 116 <div class="entry-utility"> 120 117 <?php twentyten_posted_on(); ?> 121 118 <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> 123 120 <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?> 124 121 </div><!-- .entry-utility --> 125 122 </div><!-- #post-## --> … … 128 125 129 126 <?php else : ?> 130 127 <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> 132 129 133 130 <div class="entry-meta"> 134 131 <?php twentyten_posted_on(); ?> … … 161 158 </span> 162 159 <span class="meta-sep">|</span> 163 160 <?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> 165 162 <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?> 166 163 </div><!-- .entry-utility --> 167 164 </div><!-- #post-## -->