WordPress.org

Make WordPress Core

Changeset 9887


Ignore:
Timestamp:
11/25/08 22:25:21 (6 years ago)
Author:
ryan
Message:

Contextual ngettext from nbachiyski. fixes #8128

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-pages.php

    r9835 r9887  
    7272 
    7373$post_stati  = array(   //  array( adj, noun ) 
    74         'publish' => array(__('Published'), __('Published pages'), __ngettext_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>')), 
    75         'future' => array(__('Scheduled'), __('Scheduled pages'), __ngettext_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>')), 
    76         'pending' => array(__('Pending Review'), __('Pending pages'), __ngettext_noop('Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>')), 
    77         'draft' => array(__('Draft'), _c('Drafts|manage posts header'), __ngettext_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')), 
    78         '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>')) 
     74        'publish' => array(__('Published|page'), __('Published pages'), _n_noop('Published <span class="count">(%s)</span>|page', 'Published <span class="count">(%s)</span>')), 
     75        'future' => array(__('Scheduled|page'), __('Scheduled pages'), _n_noop('Scheduled <span class="count">(%s)</span>|page', 'Scheduled <span class="count">(%s)</span>')), 
     76        'pending' => array(__('Pending Review|page'), __('Pending pages'), _n_noop('Pending Review <span class="count">(%s)</span>|page', 'Pending Review <span class="count">(%s)</span>')), 
     77        'draft' => array(__('Draft|page'), _c('Drafts|manage posts header'), _n_noop('Draft <span class="count">(%s)</span>|page', 'Drafts <span class="count">(%s)</span>')), 
     78        '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>')) 
    7979    ); 
    8080 
     
    148148        $class = ' class="current"'; 
    149149 
    150     $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>'; 
     150    $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>'; 
    151151} 
    152152echo implode( " |</li>\n", $status_links ) . '</li>'; 
  • trunk/wp-includes/l10n.php

    r9212 r9887  
    7171} 
    7272 
     73function before_last_bar( $string ) { 
     74    $last_bar = strrpos( $string, '|' ); 
     75    if ( false == $last_bar ) 
     76        return $string; 
     77    else 
     78        return substr( $string, 0, $last_bar ); 
     79} 
     80 
    7381/** 
    7482 * Retrieve the translated text and strip context. 
     
    8795 * @return string Translated text 
    8896 */ 
    89 function translate_with_context($text, $domain = 'default') { 
    90     $whole = translate($text, $domain); 
    91     $last_bar = strrpos($whole, '|'); 
    92     if ( false == $last_bar ) { 
    93         return $whole; 
    94     } else { 
    95         return substr($whole, 0, $last_bar); 
    96     } 
     97function translate_with_context( $text, $domain = 'default' ) { 
     98    return before_last_bar( translate( $text, $domain ) ); 
     99 
    97100} 
    98101 
     
    183186 
    184187/** 
     188 * @see __ngettext() An alias of __ngettext 
     189 * 
     190 */ 
     191function _n() { 
     192    $args = func_get_args(); 
     193    return call_user_func_array('__ngettext', $args); 
     194} 
     195 
     196/** 
     197 * @see _n() A version of _n(), which supports contexts -- 
     198 * strips everything from the translation after the last bar 
     199 * 
     200 */ 
     201function _nc( $single, $plural, $number, $domain = 'default' ) { 
     202    return before_last_bar( __ngettext( $single, $plural, $number, $domain ) ); 
     203} 
     204 
     205/** 
    185206 * Register plural strings in POT file, but don't translate them. 
    186207 * 
     
    209230 
    210231/** 
     232 * @see __ngettext_noop() An alias of __ngettext_noop() 
     233 * 
     234 */ 
     235function _n_noop() { 
     236    $args = func_get_args(); 
     237    return call_user_func_array('__ngettext_noop', $args); 
     238} 
     239 
     240/** 
    211241 * Loads MO file into the list of domains. 
    212242 * 
Note: See TracChangeset for help on using the changeset viewer.