Skip to:
Content

BuddyPress.org

Changeset 9047


Ignore:
Timestamp:
09/27/2014 12:49:45 AM (6 years ago)
Author:
boonebgorges
Message:

Use _n() for translations in bp_get_group_member_count()

The previous technique (manually switching between 1 and not-1) does not
provide adequate internationalizability for all languages.

Adds unit tests.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-template.php

    r9046 r9047  
    16341634        global $groups_template;
    16351635
    1636         if ( 1 == (int) $groups_template->group->total_member_count )
    1637             return apply_filters( 'bp_get_group_member_count', sprintf( __( '%s member', 'buddypress' ), bp_core_number_format( $groups_template->group->total_member_count ) ) );
    1638         else
    1639             return apply_filters( 'bp_get_group_member_count', sprintf( __( '%s members', 'buddypress' ), bp_core_number_format( $groups_template->group->total_member_count ) ) );
     1636        if ( isset( $groups_template->group->total_member_count ) ) {
     1637            $count = (int) $groups_template->group->total_member_count;
     1638        } else {
     1639            $count = 0;
     1640        }
     1641
     1642        $count_string = sprintf( _n( '%s member', '%s members', $count, 'buddypress' ), bp_core_number_format( $count ) );
     1643
     1644        return apply_filters( 'bp_get_group_member_count', $count_string );
    16401645    }
    16411646
  • trunk/tests/phpunit/testcases/groups/template.php

    r8958 r9047  
    797797        $this->set_current_user( $old_user );
    798798    }
     799
     800    /**
     801     * @group bp_get_group_member_count
     802     */
     803    public function test_bp_get_group_member_count_0_members() {
     804        global $groups_template;
     805        $gt = $groups_template;
     806        $groups_template = new stdClass;
     807        $groups_template->group = new stdClass;
     808        $groups_template->group->total_member_count = 0;
     809
     810        $found = bp_get_group_member_count();
     811
     812        $groups_template = $gt;
     813
     814        $this->assertSame( '0 members', $found );
     815    }
     816
     817    /**
     818     * @group bp_get_group_member_count
     819     */
     820    public function test_bp_get_group_member_count_1_member() {
     821        global $groups_template;
     822        $gt = $groups_template;
     823        $groups_template = new stdClass;
     824        $groups_template->group = new stdClass;
     825        $groups_template->group->total_member_count = 1;
     826
     827        $found = bp_get_group_member_count();
     828
     829        $groups_template = $gt;
     830
     831        $this->assertSame( '1 member', $found );
     832    }
     833
     834    /**
     835     * @group bp_get_group_member_count
     836     */
     837    public function test_bp_get_group_member_count_2_members() {
     838        global $groups_template;
     839        $gt = $groups_template;
     840        $groups_template = new stdClass;
     841        $groups_template->group = new stdClass;
     842        $groups_template->group->total_member_count = 2;
     843
     844        $found = bp_get_group_member_count();
     845
     846        $groups_template = $gt;
     847
     848        $this->assertSame( '2 members', $found );
     849    }
    799850}
Note: See TracChangeset for help on using the changeset viewer.