WordPress.org

Make WordPress Core

Changeset 9834


Ignore:
Timestamp:
11/21/2008 06:12:57 PM (9 years ago)
Author:
westi
Message:

Ensure tag cloud topic(s) tooltips can be translated. Fixes #7989 props nbachiyski.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/category-template.php

    r9599 r9834  
    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()}
     
    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 *
     
    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.
     
    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
     
    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>";
Note: See TracChangeset for help on using the changeset viewer.