Make WordPress Core


Ignore:
Timestamp:
02/07/2023 05:26:14 PM (2 years ago)
Author:
audrasjb
Message:

I18N: Introduce word_count_type property to WP_Locale.

This changesets adds a word_count_type property, so that it does not need to be translated separately across multiple projects.

List of changes:

  • New property: WP_Locale::word_count_type.
  • New method: WP_Locale::get_word_count_type().
  • New function: wp_get_word_count_type() as a wrapper for WP_Locale::get_word_count_type().
  • All _x( 'words', 'Word count type. Do not translate!' ) strings have been replaced with a call to wp_get_word_count_type().

Props pedromendonca, desrosj, costdev, mukesh27, johnbillion.
Fixes #56698.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/locale.php

    r55047 r55279  
    174174        $this->assertFalse( $this->locale->is_rtl() );
    175175    }
     176
     177    /**
     178     * Tests that `WP_Locale::get_word_count_type()` returns
     179     * the appropriate value.
     180     *
     181     * @ticket 56698
     182     *
     183     * @covers WP_Locale::get_word_count_type
     184     *
     185     * @dataProvider data_get_word_count_type
     186     *
     187     * @param string $word_count_type The word count type.
     188     * @param string $expected        The expected return value.
     189     */
     190    public function test_get_word_count_type( $word_count_type, $expected ) {
     191        if ( is_string( $word_count_type ) ) {
     192            $this->locale->word_count_type = $word_count_type;
     193
     194        }
     195
     196        $this->assertSame( $expected, $this->locale->get_word_count_type() );
     197    }
     198
     199    /**
     200     * Data provider.
     201     *
     202     * @return array[]
     203     */
     204    public function data_get_word_count_type() {
     205        return array(
     206            'default'                   => array(
     207                'word_count_type' => null,
     208                'expected'        => 'words',
     209            ),
     210            'empty string'              => array(
     211                'word_count_type' => '',
     212                'expected'        => 'words',
     213            ),
     214            'an invalid option - "foo"' => array(
     215                'word_count_type' => 'foo',
     216                'expected'        => 'words',
     217            ),
     218            'a valid option - "words"'  => array(
     219                'word_count_type' => 'words',
     220                'expected'        => 'words',
     221            ),
     222            'a valid option - "characters_excluding_spaces"' => array(
     223                'word_count_type' => 'characters_excluding_spaces',
     224                'expected'        => 'characters_excluding_spaces',
     225            ),
     226            'a valid option - "characters_including_spaces"' => array(
     227                'word_count_type' => 'characters_including_spaces',
     228                'expected'        => 'characters_including_spaces',
     229            ),
     230        );
     231    }
    176232}
    177233
Note: See TracChangeset for help on using the changeset viewer.