WordPress.org

Make WordPress Core

Changeset 16073


Ignore:
Timestamp:
10/29/10 13:12:14 (3 years ago)
Author:
nbachiyski
Message:

Introduce and use translate_nooped_plural(). Fixes #13996

  • _n_noop() and _nx_noop() now return associative arrays for greater clarity
  • translate_nooped_plural() takes one such associative array and translates it
  • it works on both the result from _n_noop() and from _nx_noop()
  • this breaks backwards compatibility, but I doubt any plugin uses it (I will do a global grep to confirm)
  • translate_nooped_plural() is applied where applicable
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/list-table-comments.php

    r16061 r16073  
    150150            */ 
    151151            $status_links[$status] = "<li class='$status'><a href='$link'$class>" . sprintf( 
    152                 _n( $label[0], $label[1], $num_comments->$status ), 
     152                translate_nooped_plural( $label, $num_comments->$status ), 
    153153                number_format_i18n( $num_comments->$status ) 
    154154            ) . '</a>'; 
  • trunk/wp-admin/includes/list-table-media.php

    r16061 r16073  
    6868                $class = ' class="current"'; 
    6969            if ( !empty( $num_posts[$mime_type] ) ) 
    70                 $type_links[$mime_type] = "<li><a href='upload.php?post_mime_type=$mime_type'$class>" . sprintf( _n( $label[2][0], $label[2][1], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</a>'; 
     70                $type_links[$mime_type] = "<li><a href='upload.php?post_mime_type=$mime_type'$class>" . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</a>'; 
    7171        } 
    7272        $type_links['detached'] = '<li><a href="upload.php?detached=1"' . ( $detached ? ' class="current"' : '' ) . '>' . sprintf( _nx( 'Unattached <span class="count">(%s)</span>', 'Unattached <span class="count">(%s)</span>', $total_orphans, 'detached files' ), number_format_i18n( $total_orphans ) ) . '</a>'; 
  • trunk/wp-admin/includes/list-table-posts.php

    r16061 r16073  
    171171                $class = ' class="current"'; 
    172172 
    173             $status_links[$status_name] = "<li><a href='edit.php?post_status=$status_name&amp;post_type=$post_type'$class>" . sprintf( _n( $status->label_count[0], $status->label_count[1], $num_posts->$status_name ), number_format_i18n( $num_posts->$status_name ) ) . '</a>'; 
     173            $status_links[$status_name] = "<li><a href='edit.php?post_status=$status_name&amp;post_type=$post_type'$class>" . sprintf( translate_nooped_plural( $status->label_count, $num_posts->$status_name ), number_format_i18n( $num_posts->$status_name ) ) . '</a>'; 
    174174        } 
    175175 
  • trunk/wp-admin/includes/media.php

    r16061 r16073  
    18641864        $class = ' class="current"'; 
    18651865 
    1866     $type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false))) . "'$class>" . sprintf(_n($label[2][0], $label[2][1], $num_posts[$mime_type]), "<span id='$mime_type-counter'>" . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>'; 
     1866    $type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false))) . "'$class>" . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), "<span id='$mime_type-counter'>" . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>'; 
    18671867} 
    18681868echo implode(' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>'; 
  • trunk/wp-includes/l10n.php

    r15590 r16073  
    268268 *  ... 
    269269 *  $message = $messages[$type]; 
    270  *  $usable_text = sprintf(_n($message[0], $message[1], $count), $count); 
     270 *  $usable_text = sprintf( translate_nooped_plural( $message, $count ), $count ); 
    271271 * 
    272272 * @since 2.5 
     
    275275 * @return array array($single, $plural) 
    276276 */ 
    277 function _n_noop( $single, $plural ) { 
    278     return array( $single, $plural ); 
     277function _n_noop( $singular, $plural ) { 
     278    return array( 'singular' => $singular, 'plural' => $plural, 'context' => null ); 
    279279} 
    280280 
     
    284284 * @see _n_noop() 
    285285 */ 
    286 function _nx_noop( $single, $plural, $context ) { 
    287     return array( $single, $plural, $context ); 
     286function _nx_noop( $singular, $plural, $context ) { 
     287    return array( 'singular' => $singular, 'plural' => $plural, 'context' => $context ); 
     288} 
     289 
     290/** 
     291 * Translate the result of _n_noop() or _nx_noop() 
     292 *  
     293 * @since 3.1 
     294 * @param array $nooped_plural array with singular, plural and context keys, usually the result of _n_noop() or _nx_noop() 
     295 * @param int $count number of objects 
     296 * @param string $domain Optional. The domain identifier the text should be retrieved in 
     297 */ 
     298function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) { 
     299    if ( $nooped_plural['context'] ) 
     300        return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain ); 
     301    else 
     302        return _n( $nooped_plural['singular'], $nooped_plural['plural'], $count, $domain ); 
    288303} 
    289304 
Note: See TracChangeset for help on using the changeset viewer.