From b6da4f7a1322f943bf7735d57d28af61bc3a7381 Mon Sep 17 00:00:00 2001 From: westi Date: Fri, 21 Nov 2008 18:12:57 +0000 Subject: [PATCH] Ensure tag cloud topic(s) tooltips can be translated. Fixes #7989 props nbachiyski. git-svn-id: http://svn.automattic.com/wordpress/trunk@9834 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/category-template.php | 36 ++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index a6d7cb30cd..65bb945e04 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -536,9 +536,9 @@ function wp_list_categories( $args = '' ) { * The 'number' argument is how many tags to return. By default, the limit will * be to return the top 45 tags in the tag cloud list. * - * The 'single_text' and 'multiple_text' arguments are used for the link title - * for the tag link. If the tag only has one, it will use the text in the - * 'single_text' or if it has more than one it will use 'multiple_text' instead. +* The 'topic_count_text_callback' argument is a function, which, given the count + * of the posts with that tag, returns a text for the tooltip of the tag link. + * @see default_topic_count_text * * The 'exclude' and 'include' arguments are used for the {@link get_tags()} * function. Only one should be used, because only one will be used and the @@ -584,6 +584,16 @@ function wp_tag_cloud( $args = '' ) { echo $return; } +/** + * Default text for tooltip for tag links + * + * @param integer $count number of posts with that tag + * @return string text for the tooltip of a tag link. + */ +function default_topic_count_text( $count ) { + return sprintf( __ngettext('%s topic', '%s topics', $count), number_format_i18n( $count ) ); +} + /** * Generates a tag cloud (heatmap) from provided data. * @@ -601,9 +611,10 @@ function wp_tag_cloud( $args = '' ) { * The 'number' argument is how many tags to return. By default, the limit will * be to return the entire tag cloud list. * - * The 'single_text' and 'multiple_text' arguments are used for the link title - * for the tag link. If the tag only has one, it will use the text in the - * 'single_text' or if it has more than one it will use 'multiple_text' instead. + * The 'topic_count_text_callback' argument is a function, which given the count + * of the posts with that tag returns a text for the tooltip of the tag link. + * @see default_topic_count_text + * * * @todo Complete functionality. * @since 2.3.0 @@ -617,9 +628,18 @@ function wp_generate_tag_cloud( $tags, $args = '' ) { $defaults = array( 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0, 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC', - 'single_text' => '%d topic', 'multiple_text' => '%d topics' + 'topic_count_text_callback' => 'default_topic_count_text', ); + + if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) { + $body = 'return sprintf ( + __ngettext('.var_export($args['single_text'], true).', '.var_export($args['multiple_text'], true).', $count), + number_format_i18n( $count ));'; + $args['topic_count_text_callback'] = create_function('$count', $body); + } + $args = wp_parse_args( $args, $defaults ); + extract( $args ); if ( empty( $tags ) ) @@ -666,7 +686,7 @@ function wp_generate_tag_cloud( $tags, $args = '' ) { $tag_link = '#' != $tag->link ? clean_url( $tag->link ) : '#'; $tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key; $tag_name = $tags[ $key ]->name; - $a[] = "$tag_name"; }