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


git-svn-id: http://svn.automattic.com/wordpress/trunk@16073 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nbachiyski 2010-10-29 13:12:14 +00:00
parent d8b886461a
commit 9f5c506a9f
5 changed files with 24 additions and 9 deletions

View File

@ -149,7 +149,7 @@ class WP_Comments_Table extends WP_List_Table {
$link = add_query_arg( 's', esc_attr( stripslashes( $_REQUEST['s'] ) ), $link );
*/
$status_links[$status] = "<li class='$status'><a href='$link'$class>" . sprintf(
_n( $label[0], $label[1], $num_comments->$status ),
translate_nooped_plural( $label, $num_comments->$status ),
number_format_i18n( $num_comments->$status )
) . '</a>';
}

View File

@ -67,7 +67,7 @@ class WP_Media_Table extends WP_List_Table {
if ( !empty($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
$class = ' class="current"';
if ( !empty( $num_posts[$mime_type] ) )
$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>';
$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>';
}
$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>';

View File

@ -170,7 +170,7 @@ class WP_Posts_Table extends WP_List_Table {
if ( isset($_REQUEST['post_status']) && $status_name == $_REQUEST['post_status'] )
$class = ' class="current"';
$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>';
$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>';
}
if ( ! empty( $this->sticky_posts_count ) ) {

View File

@ -1863,7 +1863,7 @@ foreach ( $post_mime_types as $mime_type => $label ) {
if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
$class = ' class="current"';
$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>';
$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>';
}
echo implode(' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>';
unset($type_links);

View File

@ -267,15 +267,15 @@ function _nx($single, $plural, $number, $context, $domain = 'default') {
* );
* ...
* $message = $messages[$type];
* $usable_text = sprintf(_n($message[0], $message[1], $count), $count);
* $usable_text = sprintf( translate_nooped_plural( $message, $count ), $count );
*
* @since 2.5
* @param string $single Single form to be i18ned
* @param string $plural Plural form to be i18ned
* @return array array($single, $plural)
*/
function _n_noop( $single, $plural ) {
return array( $single, $plural );
function _n_noop( $singular, $plural ) {
return array( 'singular' => $singular, 'plural' => $plural, 'context' => null );
}
/**
@ -283,8 +283,23 @@ function _n_noop( $single, $plural ) {
*
* @see _n_noop()
*/
function _nx_noop( $single, $plural, $context ) {
return array( $single, $plural, $context );
function _nx_noop( $singular, $plural, $context ) {
return array( 'singular' => $singular, 'plural' => $plural, 'context' => $context );
}
/**
* Translate the result of _n_noop() or _nx_noop()
*
* @since 3.1
* @param array $nooped_plural array with singular, plural and context keys, usually the result of _n_noop() or _nx_noop()
* @param int $count number of objects
* @param string $domain Optional. The domain identifier the text should be retrieved in
*/
function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) {
if ( $nooped_plural['context'] )
return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain );
else
return _n( $nooped_plural['singular'], $nooped_plural['plural'], $count, $domain );
}
/**