Ticket #13651: comments-number-i18n-custom-parsing.diff
File comments-number-i18n-custom-parsing.diff, 17.7 KB (added by , 14 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( 0 => $singular, 1 => $plural, '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( 0 => $singular, 1 => $plural, 2 => $context, '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( $no_comments = null, $one_comment = null, $many_comments = null, $domain = 'default' ) { 568 return _get_comments_number_text_helper( $no_comments, $one_comment, $many_comments, null, $domain ); 569 } 576 570 571 function get_comments_number_text_x( $no_comments = null, $one_comment = null, $many_comments = null, $context = null, $domain = 'default' ) { 572 return _get_comments_number_text_helper( $no_comments, $one_comment, $many_comments, $context, $domain ); 573 } 574 575 /** 576 * @access private 577 */ 578 function _get_comments_number_text_helper( $no_comments = null, $one_comment = null, $many_comments = null, $context, $domain = 'default' ) { 577 579 $number = get_comments_number(); 580 if ( 0 == $number ) { 581 $text = is_null( $no_comments )? __( 'No Comments' ) : translate( $no_comments ); 582 } else { 583 $format = _get_comments_number_translated_format( $number, $one_comment, $many_comments, $context, $domain); 584 $text = sprintf( $format, number_format_i18n( $number) ); 585 } 586 return apply_filters( 'get_comments_number_text', $text, $number ); 587 588 } 578 589 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; 590 /** 591 * @access private 592 */ 593 function _get_comments_number_translated_format( $number, $one_comment, $many_comments, $context, $domain ) { 594 if ( is_null( $one_comment ) || is_null( $many_comments) ) 595 return $context? _nx( '1 Comment', '%s Comments', $number, $context, $domain ) : _n( '1 Comment', '%s Comments', $number, $context, $domain ); 596 else 597 return $context? _nx( $one_comment, $many_comments, $number, $context, $domain ) : _n( $one_comment, $many_comments, $number, $domain ); 598 } 585 599 586 echo apply_filters('comments_number', $output, $number); 600 function comments_number_text( $no_comments = null, $one_comment = null, $many_comments = null, $domain = 'default' ) { 601 $number = get_comments_number(); 602 $after_old_filter = apply_filters( 'comments_number', get_comments_number_text( $no_comments, $one_comment, $many_comments, $domain ), $number ); 603 echo apply_filters( 'comments_number_text', $after_old_filter, $number ); 587 604 } 588 605 606 function comments_number_text_x( $no_comments = null, $one_comment = null, $many_comments = null, $context, $domain = 'default' ) { 607 $number = get_comments_number(); 608 $after_old_filter = apply_filters( 'comments_number', get_comments_number_text_x( $no_comments, $one_comment, $many_comments, $context, $domain ), $number ); 609 echo apply_filters( 'comments_number_text', $after_old_filter, $number ); 610 } 611 612 589 613 /** 614 * Return an HTML link to the current post's comments. The arguments are the same as those of {@link comments_number_link()} 615 * 616 */ 617 function get_comments_number_link( $no_comments = null, $one_comment = null, $many_comments = null, $domain = 'default', $disabled = null, $attrs = array() ) { 618 global $wpcommentspopupfile, $wpcommentsjavascript; 619 $number = get_comments_number(); 620 621 $disabled = is_null( $disabled )? __( 'Comments Off' ) : translate( $disabled ); 622 623 if ( 0 == $number && !comments_open() && !pings_open() ) { 624 return "<span ".apply_filters( 'get_comments_number_link_attrs', $attrs ).">$disabled</span>"; 625 } 626 627 if ( post_password_required() ) { 628 return __( 'Enter your password to view comments.' ); 629 } 630 631 if ( post_password_required() ) { 632 echo __('Enter your password to view comments.'); 633 return; 634 } 635 636 $attrs['href'] = $number? get_comments_link() : get_permalink() . '#respond'; 637 if ( isset( $wpcommentsjavascript ) && $wpcommentsjavascript ) { 638 $home = $wpcommentspopupfile? get_option( 'siteurl' ) : home_url(); 639 $attrs['href'] = $home . '/' . $wpcommentspopupfile . '?comments_popup=' . get_the_ID(); 640 $attrs['onclick'] = 'wpopen(this.href); return false;'; 641 } 642 $attrs['title'] = sprintf( __('Comment on %s'), get_the_title() ); 643 $attrs = apply_filters( 'get_comments_number_link_attrs', $attrs ); 644 645 $text = get_comments_number_text( $no_comments, $one_comment, $many_comments, $domain ); 646 $html_attrs = wp_html_attributes( $attrs ); 647 return "<a $html_attrs>$text</a>"; 648 } 649 650 /** 651 * Display an HTML link to the current post's comments 652 * 653 * @param string $zero text if there are no comments. Optional. Default is 'No Comments' 654 * @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 655 * @param string $disabled text if comments are disabled. Options. Default is 'Comments Off' 656 * @param array $attrs associative array of html attributes and their values (raw, not escaped) 657 */ 658 function comments_number_link( $no_comments = null, $one_comment = null, $many_comments = null, $domain = 'default', $disabled = null, $attrs = array() ) { 659 echo get_comments_number_link( $no_comments, $one_comment, $many_comments, $domain, $disabled, $attrs ); 660 } 661 662 /** 590 663 * Retrieve the text of the current comment. 591 664 * 592 665 * @since 1.5.0 … … 949 1022 } 950 1023 951 1024 /** 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 1025 * Retrieve HTML content for reply to comment link. 1021 1026 * 1022 1027 * The default arguments that can be override are 'add_below', 'respond_id', -
wp-includes/formatting.php
2898 2898 2899 2899 } 2900 2900 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 */ 2912 function 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 } 2920 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( '1 Comment', '% Comments', get_comments_number(), 'twentyten' );59 ?>60 61 58 <?php /* How to display posts of the Gallery format. The gallery category is the old way. */ ?> 62 59 63 60 <?php if ( 'gallery' == get_post_format( $post->ID ) || in_category( _x( 'gallery', 'gallery category slug', 'twentyten' ) ) ) : ?> … … 99 96 <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> 100 97 <span class="meta-sep">|</span> 101 98 <?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', '1 Comment', '%s Comments', 'twentyten' ); ?></span> 103 100 <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?> 104 101 </div><!-- .entry-utility --> 105 102 </div><!-- #post-## --> … … 122 119 <div class="entry-utility"> 123 120 <?php twentyten_posted_on(); ?> 124 121 <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', '1 Comment', '%s Comments', 'twentyten' ); ?></span> 126 123 <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?> 127 124 </div><!-- .entry-utility --> 128 125 </div><!-- #post-## --> … … 164 161 </span> 165 162 <span class="meta-sep">|</span> 166 163 <?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', '1 Comment', '%s Comments', 'twentyten' ); ?></span> 168 165 <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?> 169 166 </div><!-- .entry-utility --> 170 167 </div><!-- #post-## -->