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.


git-svn-id: https://develop.svn.wordpress.org/trunk@55279 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jb Audras
2023-02-07 17:26:14 +00:00
parent d80c313c80
commit 024946f9d1
5 changed files with 113 additions and 12 deletions

View File

@@ -173,6 +173,62 @@ class Tests_Locale extends WP_UnitTestCase {
$this->locale->text_direction = 'ltr';
$this->assertFalse( $this->locale->is_rtl() );
}
/**
* Tests that `WP_Locale::get_word_count_type()` returns
* the appropriate value.
*
* @ticket 56698
*
* @covers WP_Locale::get_word_count_type
*
* @dataProvider data_get_word_count_type
*
* @param string $word_count_type The word count type.
* @param string $expected The expected return value.
*/
public function test_get_word_count_type( $word_count_type, $expected ) {
if ( is_string( $word_count_type ) ) {
$this->locale->word_count_type = $word_count_type;
}
$this->assertSame( $expected, $this->locale->get_word_count_type() );
}
/**
* Data provider.
*
* @return array[]
*/
public function data_get_word_count_type() {
return array(
'default' => array(
'word_count_type' => null,
'expected' => 'words',
),
'empty string' => array(
'word_count_type' => '',
'expected' => 'words',
),
'an invalid option - "foo"' => array(
'word_count_type' => 'foo',
'expected' => 'words',
),
'a valid option - "words"' => array(
'word_count_type' => 'words',
'expected' => 'words',
),
'a valid option - "characters_excluding_spaces"' => array(
'word_count_type' => 'characters_excluding_spaces',
'expected' => 'characters_excluding_spaces',
),
'a valid option - "characters_including_spaces"' => array(
'word_count_type' => 'characters_including_spaces',
'expected' => 'characters_including_spaces',
),
);
}
}
class Custom_WP_Locale extends WP_Locale {