Make WordPress Core


Ignore:
Timestamp:
02/07/2023 05:26:14 PM (4 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/src/wp-includes/class-wp-locale.php

    r55047 r55279  
    112112         */
    113113        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;
    114124
    115125        /**
     
    237247                        $this->text_direction = 'rtl';
    238248                }
     249
     250                // Set the word count type.
     251                $this->word_count_type = $this->get_word_count_type();
    239252        }
    240253
     
    397410                return $this->list_item_separator;
    398411        }
     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        }
    399439}
Note: See TracChangeset for help on using the changeset viewer.