Skip to:
Content

bbPress.org


Ignore:
Timestamp:
08/07/2017 08:33:36 PM (8 years ago)
Author:
johnjamesjacoby
Message:

i18n: Improvements to bbp_get_time_since().

Use _n_noop() to register year/month/week/day/hour/minute/second strings in advance and _n() to actually translate them.

Fixes #3139. Props SergeyBiryukov.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/common/formatting.php

    r6573 r6645  
    624624
    625625        // Setup the strings
    626         $unknown_text   = apply_filters( 'bbp_core_time_since_unknown_text',   __( 'sometime',  'bbpress' ) );
    627         $right_now_text = apply_filters( 'bbp_core_time_since_right_now_text', __( 'right now', 'bbpress' ) );
    628         $ago_text       = apply_filters( 'bbp_core_time_since_ago_text',       __( '%s ago',    'bbpress' ) );
     626        $unknown_text   = apply_filters( 'bbp_core_time_since_unknown_text',   esc_html__( 'sometime',  'bbpress' ) );
     627        $right_now_text = apply_filters( 'bbp_core_time_since_right_now_text', esc_html__( 'right now', 'bbpress' ) );
     628        $ago_text       = apply_filters( 'bbp_core_time_since_ago_text',       esc_html__( '%s ago',    'bbpress' ) );
    629629
    630630        // array of time period chunks
    631631        $chunks = array(
    632             array( 60 * 60 * 24 * 365 , __( 'year',   'bbpress' ), __( 'years',   'bbpress' ) ),
    633             array( 60 * 60 * 24 * 30 ,  __( 'month',  'bbpress' ), __( 'months',  'bbpress' ) ),
    634             array( 60 * 60 * 24 * 7,    __( 'week',   'bbpress' ), __( 'weeks',   'bbpress' ) ),
    635             array( 60 * 60 * 24 ,       __( 'day',    'bbpress' ), __( 'days',    'bbpress' ) ),
    636             array( 60 * 60 ,            __( 'hour',   'bbpress' ), __( 'hours',   'bbpress' ) ),
    637             array( 60 ,                 __( 'minute', 'bbpress' ), __( 'minutes', 'bbpress' ) ),
    638             array( 1,                   __( 'second', 'bbpress' ), __( 'seconds', 'bbpress' ) )
     632            array( YEAR_IN_SECONDS,   '%s year',   '%s years',   _n_noop( '%s year',   '%s years',   'bbpress' ) ),
     633            array( MONTH_IN_SECONDS,  '%s month',  '%s months',  _n_noop( '%s month',  '%s months',  'bbpress' ) ),
     634            array( WEEK_IN_SECONDS,   '%s week',   '%s weeks',   _n_noop( '%s week',   '%s weeks',   'bbpress' ) ),
     635            array( DAY_IN_SECONDS,    '%s day',    '%s days',    _n_noop( '%s day',    '%s days',    'bbpress' ) ),
     636            array( HOUR_IN_SECONDS,   '%s hour',   '%s hours',   _n_noop( '%s hour',   '%s hours',   'bbpress' ) ),
     637            array( MINUTE_IN_SECONDS, '%s minute', '%s minutes', _n_noop( '%s minute', '%s minutes', 'bbpress' ) ),
     638            array( 1,                 '%s second', '%s seconds', _n_noop( '%s second', '%s seconds', 'bbpress' ) ),
    639639        );
    640640
     
    681681
    682682                // Set output var
    683                 $output = ( 1 == $count ) ? '1 '. $chunks[ $i ][1] : $count . ' ' . $chunks[ $i ][2];
     683                $output = sprintf( _n( $chunks[ $i ][1], $chunks[ $i ][2], $count, 'bbppress' ), bbp_number_format_i18n( $count ) );
    684684
    685685                // Step two: the second chunk
    686686                if ( $i + 2 < $j ) {
    687687                    $seconds2 = $chunks[ $i + 1 ][0];
    688                     $name2    = $chunks[ $i + 1 ][1];
    689688                    $count2   = floor( ( $since - ( $seconds * $count ) ) / $seconds2 );
    690689
    691690                    // Add to output var
    692691                    if ( 0 != $count2 ) {
    693                         $output .= ( 1 == $count2 ) ? _x( ',', 'Separator in time since', 'bbpress' ) . ' 1 '. $name2 : _x( ',', 'Separator in time since', 'bbpress' ) . ' ' . $count2 . ' ' . $chunks[ $i + 1 ][2];
     692                        $output .= _x( ',', 'Separator in time since', 'bbpress' ) . ' ';
     693                        $output .= sprintf( _n( $chunks[ $i + 1 ][1], $chunks[ $i + 1 ][2], $count2, 'bbppress' ), bbp_number_format_i18n( $count2 ) );
    694694                    }
    695695                }
Note: See TracChangeset for help on using the changeset viewer.