diff -r 7b1b88e27a20 -r 48c4eec2b7e6 wp/wp-includes/class-wp-locale.php --- a/wp/wp-includes/class-wp-locale.php Thu Sep 29 08:06:27 2022 +0200 +++ b/wp/wp-includes/class-wp-locale.php Fri Sep 05 18:40:08 2025 +0200 @@ -13,14 +13,16 @@ * @since 2.1.0 * @since 4.6.0 Moved to its own file from wp-includes/locale.php. */ +#[AllowDynamicProperties] class WP_Locale { /** * Stores the translated strings for the full weekday names. * * @since 2.1.0 + * @since 6.2.0 Initialized to an empty array. * @var string[] */ - public $weekday; + public $weekday = array(); /** * Stores the translated strings for the one character weekday names. @@ -31,41 +33,46 @@ * @see WP_Locale::init() for how to handle the hack. * * @since 2.1.0 + * @since 6.2.0 Initialized to an empty array. * @var string[] */ - public $weekday_initial; + public $weekday_initial = array(); /** * Stores the translated strings for the abbreviated weekday names. * * @since 2.1.0 + * @since 6.2.0 Initialized to an empty array. * @var string[] */ - public $weekday_abbrev; + public $weekday_abbrev = array(); /** * Stores the translated strings for the full month names. * * @since 2.1.0 + * @since 6.2.0 Initialized to an empty array. * @var string[] */ - public $month; + public $month = array(); /** * Stores the translated strings for the month names in genitive case, if the locale specifies. * * @since 4.4.0 + * @since 6.2.0 Initialized to an empty array. * @var string[] */ - public $month_genitive; + public $month_genitive = array(); /** * Stores the translated strings for the abbreviated month names. * * @since 2.1.0 + * @since 6.2.0 Initialized to an empty array. * @var string[] */ - public $month_abbrev; + public $month_abbrev = array(); /** * Stores the translated strings for 'am' and 'pm'. @@ -73,9 +80,10 @@ * Also the capitalized versions. * * @since 2.1.0 + * @since 6.2.0 Initialized to an empty array. * @var string[] */ - public $meridiem; + public $meridiem = array(); /** * The text direction of the locale language. @@ -91,9 +99,10 @@ * The thousands separator and decimal point values used for localizing numbers. * * @since 2.3.0 + * @since 6.2.0 Initialized to an empty array. * @var array */ - public $number_format; + public $number_format = array(); /** * The separator string used for localizing list item separator. @@ -104,6 +113,16 @@ public $list_item_separator; /** + * The word count type of the locale language. + * + * Default is 'words'. + * + * @since 6.2.0 + * @var string + */ + public $word_count_type; + + /** * Constructor which calls helper methods to set up object variables. * * @since 2.1.0 @@ -123,7 +142,6 @@ * @since 2.1.0 * * @global string $text_direction - * @global string $wp_version The WordPress version string. */ public function init() { // The weekdays. @@ -201,8 +219,10 @@ $this->meridiem['AM'] = __( 'AM' ); $this->meridiem['PM'] = __( 'PM' ); - // Numbers formatting. - // See https://www.php.net/number_format + /* + * Numbers formatting. + * See https://www.php.net/number_format + */ /* translators: $thousands_sep argument for https://www.php.net/number_format, default is ',' */ $thousands_sep = __( 'number_format_thousands_sep' ); @@ -217,7 +237,7 @@ $this->number_format['decimal_point'] = ( 'number_format_decimal_point' === $decimal_point ) ? '.' : $decimal_point; - /* translators: used between list items, there is a space after the comma */ + /* translators: Used between list items, there is a space after the comma. */ $this->list_item_separator = __( ', ' ); // Set text direction. @@ -228,6 +248,9 @@ } elseif ( 'rtl' === _x( 'ltr', 'text direction' ) ) { $this->text_direction = 'rtl'; } + + // Set the word count type. + $this->word_count_type = $this->get_word_count_type(); } /** @@ -332,6 +355,7 @@ * * For backward compatibility only. * + * @since 2.1.0 * @deprecated For backward compatibility only. * * @global array $weekday @@ -339,8 +363,6 @@ * @global array $weekday_abbrev * @global array $month * @global array $month_abbrev - * - * @since 2.1.0 */ public function register_globals() { $GLOBALS['weekday'] = $this->weekday; @@ -388,4 +410,30 @@ public function get_list_item_separator() { return $this->list_item_separator; } + + /** + * Retrieves the localized word count type. + * + * @since 6.2.0 + * + * @return string Localized word count type. Possible values are `characters_excluding_spaces`, + * `characters_including_spaces`, or `words`. Defaults to `words`. + */ + public function get_word_count_type() { + + /* + * translators: If your word count is based on single characters (e.g. East Asian characters), + * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'. + * Do not translate into your own language. + */ + $word_count_type = is_null( $this->word_count_type ) ? _x( 'words', 'Word count type. Do not translate!' ) : $this->word_count_type; + + // Check for valid types. + if ( 'characters_excluding_spaces' !== $word_count_type && 'characters_including_spaces' !== $word_count_type ) { + // Defaults to 'words'. + $word_count_type = 'words'; + } + + return $word_count_type; + } }