Make WordPress Core

Changeset 33440


Ignore:
Timestamp:
07/27/2015 11:18:55 AM (9 years ago)
Author:
iseulde
Message:

Editor: word count: better names for types.

Also fix it in wp_trim_words().

Fixes #30966.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/word-count.js

    r33344 r33440  
    6262        astralRegExp: /[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
    6363        wordsRegExp: /\S\s+/g,
    64         charactersRegExp: /\S/g,
    65         allRegExp: /[^\f\n\r\t\v\u00AD\u2028\u2029]/g,
     64        characters_excluding_spacesRegExp: /\S/g,
     65        characters_including_spacesRegExp: /[^\f\n\r\t\v\u00AD\u2028\u2029]/g,
    6666        l10n: window.wordCountL10n || {}
    6767    };
     
    7272        type = type || this.settings.l10n.type;
    7373
    74         if ( type !== 'characters' && type !== 'all' ) {
     74        if ( type !== 'characters_excluding_spaces' && type !== 'characters_including_spaces' ) {
    7575            type = 'words';
    7676        }
  • trunk/src/wp-includes/formatting.php

    r33411 r33440  
    28132813 */
    28142814function wp_trim_words( $text, $num_words = 55, $more = null ) {
    2815     if ( null === $more )
     2815    if ( null === $more ) {
    28162816        $more = __( '…' );
     2817    }
     2818
    28172819    $original_text = $text;
    28182820    $text = wp_strip_all_tags( $text );
    2819     /* translators: If your word count is based on single characters (East Asian characters),
    2820        enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */
    2821     if ( 'characters' == _x( 'words', 'word count: words or characters?' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) {
     2821
     2822    /* translators: If your word count is based on single characters (e.g. East Asian characters),
     2823       enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
     2824       Do not translate into your own language. */
     2825    if ( strpos( _x( 'words', 'Word count type. Do not translate!' ), 'characters' ) === 0 && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) {
    28222826        $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
    28232827        preg_match_all( '/./u', $text, $words_array );
     
    28282832        $sep = ' ';
    28292833    }
     2834
    28302835    if ( count( $words_array ) > $num_words ) {
    28312836        array_pop( $words_array );
     
    28352840        $text = implode( $sep, $words_array );
    28362841    }
     2842
    28372843    /**
    28382844     * Filter the text content after words have been trimmed.
  • trunk/src/wp-includes/script-loader.php

    r33426 r33440  
    402402    $scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array(), false, 1 );
    403403    did_action( 'init' ) && $scripts->localize( 'word-count', 'wordCountL10n', array(
    404         /* translators: If your word count is based on single characters (East Asian characters),
    405            enter 'characters', or 'all' to include spaces. Otherwise, enter 'words'.
     404        /* translators: If your word count is based on single characters (e.g. East Asian characters),
     405           enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
    406406           Do not translate into your own language. */
    407         'type' => _x( 'words', 'word count: words, characters or all?' ),
     407        'type' => _x( 'words', 'Word count type. Do not translate!' ),
    408408        'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array()
    409409    ) );
  • trunk/tests/qunit/wp-admin/js/word-count.js

    r33344 r33440  
    88                string: 'one two three',
    99                words: 3,
    10                 characters: 11,
    11                 all: 13
     10                characters_excluding_spaces: 11,
     11                characters_including_spaces: 13
    1212            },
    1313            {
     
    1515                string: 'one <em class="test">two</em><br />three',
    1616                words: 3,
    17                 characters: 11,
    18                 all: 12
     17                characters_excluding_spaces: 11,
     18                characters_including_spaces: 12
    1919            },
    2020            {
     
    2222                string: 'one\ntwo\nthree',
    2323                words: 3,
    24                 characters: 11,
    25                 all: 11
     24                characters_excluding_spaces: 11,
     25                characters_including_spaces: 11
    2626            },
    2727            {
     
    2929                string: 'one&nbsp;two&#160;three',
    3030                words: 3,
    31                 characters: 11,
    32                 all: 13
     31                characters_excluding_spaces: 11,
     32                characters_including_spaces: 13
    3333            },
    3434            {
     
    3636                string: 'It\'s two three \u2026 4?',
    3737                words: 3,
    38                 characters: 15,
    39                 all: 19
     38                characters_excluding_spaces: 15,
     39                characters_including_spaces: 19
    4040            },
    4141            {
     
    4343                string: 'one\u2014two--three',
    4444                words: 3,
    45                 characters: 14,
    46                 all: 14
     45                characters_excluding_spaces: 14,
     46                characters_including_spaces: 14
    4747            },
    4848            {
     
    5050                string: 'one [shortcode attribute="value"]two[/shortcode]three',
    5151                words: 3,
    52                 characters: 11,
    53                 all: 12
     52                characters_excluding_spaces: 11,
     53                characters_including_spaces: 12
    5454            },
    5555            {
     
    5757                string: '\uD83D\uDCA9',
    5858                words: 1,
    59                 characters: 1,
    60                 all: 1
     59                characters_excluding_spaces: 1,
     60                characters_including_spaces: 1
    6161            },
    6262            {
     
    6464                string: 'one<!-- comment -->two three',
    6565                words: 2,
    66                 characters: 11,
    67                 all: 12
     66                characters_excluding_spaces: 11,
     67                characters_including_spaces: 12
    6868            },
    6969            {
     
    7171                string: '&gt; test',
    7272                words: 1,
    73                 characters: 5,
    74                 all: 6
     73                characters_excluding_spaces: 5,
     74                characters_including_spaces: 6
    7575            }
    7676        ], function( test ) {
    77             _.each( [ 'words', 'characters', 'all' ], function( type ) {
     77            _.each( [ 'words', 'characters_excluding_spaces', 'characters_including_spaces' ], function( type ) {
    7878                assert.equal( wordCounter.count( test.string, type ), test[ type ], test.message + ' (' + type + ')' );
    7979            } );
Note: See TracChangeset for help on using the changeset viewer.