From 390984d25d34c39d7f60a2ce39e097b8a7f4e0da Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Tue, 25 Nov 2008 22:25:21 +0000 Subject: [PATCH] Contextual ngettext from nbachiyski. fixes #8128 git-svn-id: https://develop.svn.wordpress.org/trunk@9887 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/edit-pages.php | 12 +++++------ wp-includes/l10n.php | 46 ++++++++++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/wp-admin/edit-pages.php b/wp-admin/edit-pages.php index 9bd9045653..451f1ef43f 100644 --- a/wp-admin/edit-pages.php +++ b/wp-admin/edit-pages.php @@ -71,11 +71,11 @@ $parent_file = 'edit.php'; wp_enqueue_script('inline-edit-post'); $post_stati = array( // array( adj, noun ) - 'publish' => array(__('Published'), __('Published pages'), __ngettext_noop('Published (%s)', 'Published (%s)')), - 'future' => array(__('Scheduled'), __('Scheduled pages'), __ngettext_noop('Scheduled (%s)', 'Scheduled (%s)')), - 'pending' => array(__('Pending Review'), __('Pending pages'), __ngettext_noop('Pending Review (%s)', 'Pending Review (%s)')), - 'draft' => array(__('Draft'), _c('Drafts|manage posts header'), __ngettext_noop('Draft (%s)', 'Drafts (%s)')), - 'private' => array(__('Private'), __('Private pages'), __ngettext_noop('Private (%s)', 'Private (%s)')) + 'publish' => array(__('Published|page'), __('Published pages'), _n_noop('Published (%s)|page', 'Published (%s)')), + 'future' => array(__('Scheduled|page'), __('Scheduled pages'), _n_noop('Scheduled (%s)|page', 'Scheduled (%s)')), + 'pending' => array(__('Pending Review|page'), __('Pending pages'), _n_noop('Pending Review (%s)|page', 'Pending Review (%s)')), + 'draft' => array(__('Draft|page'), _c('Drafts|manage posts header'), _n_noop('Draft (%s)|page', 'Drafts (%s)')), + 'private' => array(__('Private|page'), __('Private pages'), _n_noop('Private (%s)|page', 'Private (%s)')) ); $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'] ) $class = ' class="current"'; - $status_links[] = "
  • " . sprintf( __ngettext( $label[2][0], $label[2][1], $num_posts->$status ), number_format_i18n( $num_posts->$status ) ) . ''; + $status_links[] = "
  • " . sprintf( _nc( $label[2][0], $label[2][1], $num_posts->$status ), number_format_i18n( $num_posts->$status ) ) . ''; } echo implode( " |
  • \n", $status_links ) . ''; unset($status_links); diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index 6b9484e2af..ed03835b66 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -70,6 +70,14 @@ function translate($text, $domain = 'default') { 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. * @@ -86,14 +94,9 @@ function translate($text, $domain = 'default') { * @param string $domain Domain to retrieve the translated text * @return string Translated text */ -function translate_with_context($text, $domain = 'default') { - $whole = translate($text, $domain); - $last_bar = strrpos($whole, '|'); - if ( false == $last_bar ) { - return $whole; - } else { - return substr($whole, 0, $last_bar); - } +function translate_with_context( $text, $domain = 'default' ) { + return before_last_bar( translate( $text, $domain ) ); + } /** @@ -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. * @@ -207,6 +228,15 @@ function __ngettext_noop($single, $plural, $number=1, $domain = 'default') { 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. *