Ticket #30966: 30966.16.patch
File 30966.16.patch, 6.2 KB (added by , 9 years ago) |
---|
-
src/wp-admin/js/word-count.js
61 61 ].join( '' ), 'g' ), 62 62 astralRegExp: /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, 63 63 wordsRegExp: /\S\s+/g, 64 characters RegExp: /\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, 66 66 l10n: window.wordCountL10n || {} 67 67 }; 68 68 … … 71 71 72 72 type = type || this.settings.l10n.type; 73 73 74 if ( type !== 'characters ' && type !== 'all' ) {74 if ( type !== 'characters_excluding_spaces' && type !== 'characters_including_spaces' ) { 75 75 type = 'words'; 76 76 } 77 77 -
src/wp-includes/formatting.php
2812 2812 * @return string Trimmed text. 2813 2813 */ 2814 2814 function wp_trim_words( $text, $num_words = 55, $more = null ) { 2815 if ( null === $more ) 2815 if ( null === $more ) { 2816 2816 $more = __( '…' ); 2817 } 2818 2817 2819 $original_text = $text; 2818 2820 $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' ) ) ) { 2822 2826 $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' ); 2823 2827 preg_match_all( '/./u', $text, $words_array ); 2824 2828 $words_array = array_slice( $words_array[0], 0, $num_words + 1 ); … … 2827 2831 $words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY ); 2828 2832 $sep = ' '; 2829 2833 } 2834 2830 2835 if ( count( $words_array ) > $num_words ) { 2831 2836 array_pop( $words_array ); 2832 2837 $text = implode( $sep, $words_array ); … … 2834 2839 } else { 2835 2840 $text = implode( $sep, $words_array ); 2836 2841 } 2842 2837 2843 /** 2838 2844 * Filter the text content after words have been trimmed. 2839 2845 * -
src/wp-includes/script-loader.php
401 401 402 402 $scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array(), false, 1 ); 403 403 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'. 406 406 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!' ), 408 408 'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array() 409 409 ) ); 410 410 -
tests/qunit/wp-admin/js/word-count.js
7 7 message: 'Basic test.', 8 8 string: 'one two three', 9 9 words: 3, 10 characters : 11,11 all: 1310 characters_excluding_spaces: 11, 11 characters_including_spaces: 13 12 12 }, 13 13 { 14 14 message: 'HTML tags.', 15 15 string: 'one <em class="test">two</em><br />three', 16 16 words: 3, 17 characters : 11,18 all: 1217 characters_excluding_spaces: 11, 18 characters_including_spaces: 12 19 19 }, 20 20 { 21 21 message: 'Line breaks.', 22 22 string: 'one\ntwo\nthree', 23 23 words: 3, 24 characters : 11,25 all: 1124 characters_excluding_spaces: 11, 25 characters_including_spaces: 11 26 26 }, 27 27 { 28 28 message: 'Encoded spaces.', 29 29 string: 'one two three', 30 30 words: 3, 31 characters : 11,32 all: 1331 characters_excluding_spaces: 11, 32 characters_including_spaces: 13 33 33 }, 34 34 { 35 35 message: 'Punctuation.', 36 36 string: 'It\'s two three \u2026 4?', 37 37 words: 3, 38 characters : 15,39 all: 1938 characters_excluding_spaces: 15, 39 characters_including_spaces: 19 40 40 }, 41 41 { 42 42 message: 'Em dash.', 43 43 string: 'one\u2014two--three', 44 44 words: 3, 45 characters : 14,46 all: 1445 characters_excluding_spaces: 14, 46 characters_including_spaces: 14 47 47 }, 48 48 { 49 49 message: 'Shortcodes.', 50 50 string: 'one [shortcode attribute="value"]two[/shortcode]three', 51 51 words: 3, 52 characters : 11,53 all: 1252 characters_excluding_spaces: 11, 53 characters_including_spaces: 12 54 54 }, 55 55 { 56 56 message: 'Astrals.', 57 57 string: '\uD83D\uDCA9', 58 58 words: 1, 59 characters : 1,60 all: 159 characters_excluding_spaces: 1, 60 characters_including_spaces: 1 61 61 }, 62 62 { 63 63 message: 'HTML comment.', 64 64 string: 'one<!-- comment -->two three', 65 65 words: 2, 66 characters : 11,67 all: 1266 characters_excluding_spaces: 11, 67 characters_including_spaces: 12 68 68 }, 69 69 { 70 70 message: 'HTML entity.', 71 71 string: '> test', 72 72 words: 1, 73 characters : 5,74 all: 673 characters_excluding_spaces: 5, 74 characters_including_spaces: 6 75 75 } 76 76 ], function( test ) { 77 _.each( [ 'words', 'characters ', 'all' ], function( type ) {77 _.each( [ 'words', 'characters_excluding_spaces', 'characters_including_spaces' ], function( type ) { 78 78 assert.equal( wordCounter.count( test.string, type ), test[ type ], test.message + ' (' + type + ')' ); 79 79 } ); 80 80 } );