Changeset 55279
- Timestamp:
- 02/07/2023 05:26:14 PM (21 months ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-locale.php
r55047 r55279 112 112 */ 113 113 public $list_item_separator; 114 115 /** 116 * The word count type of the locale language. 117 * 118 * Default is 'words'. 119 * 120 * @since 6.2.0 121 * @var string 122 */ 123 public $word_count_type; 114 124 115 125 /** … … 237 247 $this->text_direction = 'rtl'; 238 248 } 249 250 // Set the word count type. 251 $this->word_count_type = $this->get_word_count_type(); 239 252 } 240 253 … … 397 410 return $this->list_item_separator; 398 411 } 412 413 /** 414 * Retrieves the localized word count type. 415 * 416 * Options are 'characters_excluding_spaces', 'characters_including_spaces or 'words'. Defaults to 'words'. 417 * 418 * @since 6.2.0 419 * 420 * @return string Localized word count type. 421 */ 422 public function get_word_count_type() { 423 424 /* 425 * translators: If your word count is based on single characters (e.g. East Asian characters), 426 * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'. 427 * Do not translate into your own language. 428 */ 429 $word_count_type = is_null( $this->word_count_type ) ? _x( 'words', 'Word count type. Do not translate!' ) : $this->word_count_type; 430 431 // Check for valid types. 432 if ( 'characters_excluding_spaces' !== $word_count_type && 'characters_including_spaces' !== $word_count_type ) { 433 // Defaults to 'words'. 434 $word_count_type = 'words'; 435 } 436 437 return $word_count_type; 438 } 399 439 } -
trunk/src/wp-includes/formatting.php
r55272 r55279 3946 3946 $num_words = (int) $num_words; 3947 3947 3948 /* 3949 * translators: If your word count is based on single characters (e.g. East Asian characters), 3950 * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'. 3951 * Do not translate into your own language. 3952 */ 3953 if ( strpos( _x( 'words', 'Word count type. Do not translate!' ), 'characters' ) === 0 && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) { 3948 if ( str_starts_with( wp_get_word_count_type(), 'characters' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) { 3954 3949 $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' ); 3955 3950 preg_match_all( '/./u', $text, $words_array ); -
trunk/src/wp-includes/l10n.php
r55196 r55279 1810 1810 return $wp_locale->get_list_item_separator(); 1811 1811 } 1812 1813 /** 1814 * Retrieves the word count type based on the locale. 1815 * 1816 * @since 6.2.0 1817 * 1818 * @global WP_Locale $wp_locale WordPress date and time locale object. 1819 * 1820 * @return string Locale-specific word count type. 1821 */ 1822 function wp_get_word_count_type() { 1823 global $wp_locale; 1824 1825 return $wp_locale->get_word_count_type(); 1826 } -
trunk/src/wp-includes/script-loader.php
r55275 r55279 1832 1832 'wordCountL10n', 1833 1833 array( 1834 /* 1835 * translators: If your word count is based on single characters (e.g. East Asian characters), 1836 * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'. 1837 * Do not translate into your own language. 1838 */ 1839 'type' => _x( 'words', 'Word count type. Do not translate!' ), 1834 'type' => wp_get_word_count_type(), 1840 1835 'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array(), 1841 1836 ) -
trunk/tests/phpunit/tests/locale.php
r55047 r55279 174 174 $this->assertFalse( $this->locale->is_rtl() ); 175 175 } 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 } 176 232 } 177 233
Note: See TracChangeset
for help on using the changeset viewer.