Contextual ngettext from nbachiyski. fixes #8128

git-svn-id: https://develop.svn.wordpress.org/trunk@9887 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-11-25 22:25:21 +00:00
parent 877a39eff7
commit 390984d25d
2 changed files with 44 additions and 14 deletions

View File

@ -71,11 +71,11 @@ $parent_file = 'edit.php';
wp_enqueue_script('inline-edit-post'); wp_enqueue_script('inline-edit-post');
$post_stati = array( // array( adj, noun ) $post_stati = array( // array( adj, noun )
'publish' => array(__('Published'), __('Published pages'), __ngettext_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>')), 'publish' => array(__('Published|page'), __('Published pages'), _n_noop('Published <span class="count">(%s)</span>|page', 'Published <span class="count">(%s)</span>')),
'future' => array(__('Scheduled'), __('Scheduled pages'), __ngettext_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>')), 'future' => array(__('Scheduled|page'), __('Scheduled pages'), _n_noop('Scheduled <span class="count">(%s)</span>|page', 'Scheduled <span class="count">(%s)</span>')),
'pending' => array(__('Pending Review'), __('Pending pages'), __ngettext_noop('Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>')), 'pending' => array(__('Pending Review|page'), __('Pending pages'), _n_noop('Pending Review <span class="count">(%s)</span>|page', 'Pending Review <span class="count">(%s)</span>')),
'draft' => array(__('Draft'), _c('Drafts|manage posts header'), __ngettext_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')), 'draft' => array(__('Draft|page'), _c('Drafts|manage posts header'), _n_noop('Draft <span class="count">(%s)</span>|page', 'Drafts <span class="count">(%s)</span>')),
'private' => array(__('Private'), __('Private pages'), __ngettext_noop('<a %s>Private</a> <span class="count">(%s)</span>', '<a %s>Private</a> <span class="count">(%s)</span>')) 'private' => array(__('Private|page'), __('Private pages'), _n_noop('<a %s>Private</a> <span class="count">(%s)</span>|page', '<a %s>Private</a> <span class="count">(%s)</span>'))
); );
$query = array('post_type' => 'page', 'orderby' => 'menu_order title', 'what_to_show' => 'posts', $query = array('post_type' => 'page', 'orderby' => 'menu_order title', 'what_to_show' => 'posts',
@ -147,7 +147,7 @@ foreach ( $post_stati as $status => $label ) {
if ( isset( $_GET['post_status'] ) && $status == $_GET['post_status'] ) if ( isset( $_GET['post_status'] ) && $status == $_GET['post_status'] )
$class = ' class="current"'; $class = ' class="current"';
$status_links[] = "<li><a href='edit-pages.php?post_status=$status'$class>" . sprintf( __ngettext( $label[2][0], $label[2][1], $num_posts->$status ), number_format_i18n( $num_posts->$status ) ) . '</a>'; $status_links[] = "<li><a href='edit-pages.php?post_status=$status'$class>" . sprintf( _nc( $label[2][0], $label[2][1], $num_posts->$status ), number_format_i18n( $num_posts->$status ) ) . '</a>';
} }
echo implode( " |</li>\n", $status_links ) . '</li>'; echo implode( " |</li>\n", $status_links ) . '</li>';
unset($status_links); unset($status_links);

View File

@ -70,6 +70,14 @@ function translate($text, $domain = 'default') {
return apply_filters('gettext', $text, $text, $domain); return apply_filters('gettext', $text, $text, $domain);
} }
function before_last_bar( $string ) {
$last_bar = strrpos( $string, '|' );
if ( false == $last_bar )
return $string;
else
return substr( $string, 0, $last_bar );
}
/** /**
* Retrieve the translated text and strip context. * Retrieve the translated text and strip context.
* *
@ -87,13 +95,8 @@ function translate($text, $domain = 'default') {
* @return string Translated text * @return string Translated text
*/ */
function translate_with_context( $text, $domain = 'default' ) { function translate_with_context( $text, $domain = 'default' ) {
$whole = translate($text, $domain); return before_last_bar( translate( $text, $domain ) );
$last_bar = strrpos($whole, '|');
if ( false == $last_bar ) {
return $whole;
} else {
return substr($whole, 0, $last_bar);
}
} }
/** /**
@ -181,6 +184,24 @@ function __ngettext($single, $plural, $number, $domain = 'default') {
} }
} }
/**
* @see __ngettext() An alias of __ngettext
*
*/
function _n() {
$args = func_get_args();
return call_user_func_array('__ngettext', $args);
}
/**
* @see _n() A version of _n(), which supports contexts --
* strips everything from the translation after the last bar
*
*/
function _nc( $single, $plural, $number, $domain = 'default' ) {
return before_last_bar( __ngettext( $single, $plural, $number, $domain ) );
}
/** /**
* Register plural strings in POT file, but don't translate them. * Register plural strings in POT file, but don't translate them.
* *
@ -207,6 +228,15 @@ function __ngettext_noop($single, $plural, $number=1, $domain = 'default') {
return array($single, $plural); return array($single, $plural);
} }
/**
* @see __ngettext_noop() An alias of __ngettext_noop()
*
*/
function _n_noop() {
$args = func_get_args();
return call_user_func_array('__ngettext_noop', $args);
}
/** /**
* Loads MO file into the list of domains. * Loads MO file into the list of domains.
* *