WordPress.org

Make WordPress Core

Ticket #7989: tag-cloud-topics-text-i18n.diff

File tag-cloud-topics-text-i18n.diff, 3.4 KB (added by nbachiyski, 6 years ago)
  • wp-includes/category-template.php

     
    536536 * The 'number' argument is how many tags to return. By default, the limit will 
    537537 * be to return the top 45 tags in the tag cloud list. 
    538538 * 
    539  * The 'single_text' and 'multiple_text' arguments are used for the link title 
    540  * for the tag link. If the tag only has one, it will use the text in the 
    541  * 'single_text' or if it has more than one it will use 'multiple_text' instead. 
     539* The 'topic_count_text_callback' argument is a function, which, given the count 
     540 * of the posts  with that tag, returns a text for the tooltip of the tag link. 
     541 * @see default_topic_count_text 
    542542 * 
    543543 * The 'exclude' and 'include' arguments are used for the {@link get_tags()} 
    544544 * function. Only one should be used, because only one will be used and the 
     
    585585} 
    586586 
    587587/** 
     588 * Default text for tooltip for tag links 
     589 * 
     590 * @param integer $count number of posts with that tag 
     591 * @return string text for the tooltip of a tag link. 
     592 */ 
     593function default_topic_count_text( $count ) { 
     594        return sprintf( __ngettext('%s topic', '%s topics', $count), number_format_i18n( $count ) ); 
     595} 
     596 
     597/** 
    588598 * Generates a tag cloud (heatmap) from provided data. 
    589599 * 
    590600 * The text size is set by the 'smallest' and 'largest' arguments, which will 
     
    601611 * The 'number' argument is how many tags to return. By default, the limit will 
    602612 * be to return the entire tag cloud list. 
    603613 * 
    604  * The 'single_text' and 'multiple_text' arguments are used for the link title 
    605  * for the tag link. If the tag only has one, it will use the text in the 
    606  * 'single_text' or if it has more than one it will use 'multiple_text' instead. 
     614 * The 'topic_count_text_callback' argument is a function, which given the count 
     615 * of the posts  with that tag returns a text for the tooltip of the tag link. 
     616 * @see default_topic_count_text  
     617 *  
    607618 * 
    608619 * @todo Complete functionality. 
    609620 * @since 2.3.0 
     
    617628        $defaults = array( 
    618629                'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0, 
    619630                'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC', 
    620                 'single_text' => '%d topic', 'multiple_text' => '%d topics' 
     631                'topic_count_text_callback' => 'default_topic_count_text', 
    621632        ); 
     633         
     634        if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) { 
     635                $body = 'return sprintf (  
     636                        __ngettext('.var_export($args['single_text'], true).', '.var_export($args['multiple_text'], true).', $count), 
     637                        number_format_i18n( $count ));'; 
     638                $args['topic_count_text_callback'] = create_function('$count', $body); 
     639        } 
     640         
    622641        $args = wp_parse_args( $args, $defaults ); 
     642                 
    623643        extract( $args ); 
    624644 
    625645        if ( empty( $tags ) ) 
     
    666686                $tag_link = '#' != $tag->link ? clean_url( $tag->link ) : '#'; 
    667687                $tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key; 
    668688                $tag_name = $tags[ $key ]->name; 
    669                 $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . attribute_escape( sprintf( __ngettext( $single_text, $multiple_text, $count ), $count ) ) . "'$rel style='font-size: " . 
     689                $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . attribute_escape( $topic_count_text_callback( $count ) ) . "'$rel style='font-size: " . 
    670690                        ( $smallest + ( ( $count - $min_count ) * $font_step ) ) 
    671691                        . "$unit;'>$tag_name</a>"; 
    672692        }