Skip to:
Content
Pages
Categories
Search
Top
Bottom

I18n problem in functions.bb-core.php


  • taboo
    Member

    @vulvodynia

    Hi,

    I started investigating possibilities of translation bbPress to Polish. This language along with quite a few non-germanic languages has quite complex plural forms (3 forms instead of just 2). Not getting into much detail, because of the way functions.bb-core.php hardcodes seconds, hours, days… names it’s hard to do a proper translation.

    To do it right I’d need a function that uses “%d month” and not just “month” or “months” as defined here:

    // array of time period chunks

    $chunks = array(

    array(60 * 60 * 24 * 365 , __(‘year’) , __(‘years’)),

    array(60 * 60 * 24 * 30 , __(‘month’) , __(‘months’)),

    array(60 * 60 * 24 * 7, __(‘week’) , __(‘weeks’)),

    array(60 * 60 * 24 , __(‘day’) , __(‘days’)),

    array(60 * 60 , __(‘hour’) , __(‘hours’)),

    array(60 , __(‘minute’) , __(‘minutes’)),

    array(1 , __(‘second’) , __(‘seconds’)),

    );

    Any help would be very much appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)

  • taboo
    Member

    @vulvodynia

    I mean is there a way to separate months, seconds, etc. instead of just one output:

    $print = sprintf(__(‘%1$d %2$s’), $count, (1 == $count) ? $name : $names);


    Sam Bauers
    Participant

    @sambauers

    Hmmm, that’s lame. We should be using the plural translation functions there I think. I’ll look into it.


    Sam Bauers
    Participant

    @sambauers

    Try replacing the function bb_since with this and let me know if translation works better for you then:

    function bb_since( $original, $do_more = 0 ) {
    $today = time();

    if ( !is_numeric($original) ) {
    if ( $today < $_original = bb_gmtstrtotime( str_replace(',', ' ', $original) ) ) // Looks like bb_since was called twice
    return $original;
    else
    $original = $_original;
    }

    // array of time period chunks
    $chunks = array(
    ( 60 * 60 * 24 * 365 ), // years
    ( 60 * 60 * 24 * 30 ), // months
    ( 60 * 60 * 24 * 7 ), // weeks
    ( 60 * 60 * 24 ), // days
    ( 60 * 60 ), // hours
    ( 60 ), // minutes
    ( 1 ) // seconds
    );

    $since = $today - $original;

    for ($i = 0, $j = count($chunks); $i < $j; $i++) {
    $seconds = $chunks[$i];

    if ( 0 != $count = floor($since / $seconds) )
    break;
    }

    $trans = array(
    _n( '%d year', '%d years', $count ),
    _n( '%d month', '%d months', $count ),
    _n( '%d week', '%d weeks', $count ),
    _n( '%d day', '%d days', $count ),
    _n( '%d hour', '%d hours', $count ),
    _n( '%d minute', '%d minutes', $count ),
    _n( '%d second', '%d seconds', $count )
    );

    $print = sprintf( $trans[$i], $count );

    if ( $do_more && $i + 1 < $j) {
    $seconds2 = $chunks[$i + 1];
    if ( 0 != $count2 = floor( ($since - $seconds * $count) / $seconds2) )
    $print .= sprintf( $trans[$i + 1], $count2 );
    }
    return $print;
    }


    taboo
    Member

    @vulvodynia

    Yeah! That’s it. Works great.

    Thank you. Would you add this to 1.01 or whatever it’s going to be called?

    test drive: forum ginekologiczne


    Sam Bauers
    Participant

    @sambauers

    This was added to the 1.0.1 release that was just made.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar