WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/29/2010 01:12:14 PM (9 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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.