WordPress.org

Make WordPress Core

Changeset 19966


Ignore:
Timestamp:
02/21/2012 03:35:05 PM (6 years ago)
Author:
nacin
Message:

Allow counting by characters in lieu of a word count, for East Asian languages. First pass. see #8759.

Location:
trunk
Files:
2 edited

Legend:

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

    r17936 r19966  
    1 
    2 (function($) {
     1(function($,undefined) {
    32    wpWordCount = {
    43
     
    65            strip : /<[a-zA-Z\/][^<>]*>/g, // strip HTML tags
    76            clean : /[0-9.(),;:!?%#$¿'"_+=\\/-]+/g, // regexp to remove punctuation, etc.
    8             count : /\S\s+/g // counting regexp
     7            w : /\S\s+/g, // word-counting regexp
     8            c : /\S/g // char-counting regexp for asian languages
    99        },
    1010
    1111        block : 0,
    1212
    13         wc : function(tx) {
     13        wc : function(tx, type) {
    1414            var t = this, w = $('.word-count'), tc = 0;
     15
     16            if ( type === undefined )
     17                type = wordCountL10n.type;
     18            if ( type !== 'w' && type !== 'c' )
     19                type = 'w';
    1520
    1621            if ( t.block )
     
    2328                    tx = tx.replace( t.settings.strip, ' ' ).replace( /&nbsp;|&#160;/gi, ' ' );
    2429                    tx = tx.replace( t.settings.clean, '' );
    25                     tx.replace( t.settings.count, function(){tc++;} );
     30                    tx.replace( t.settings[type], function(){tc++;} );
    2631                }
    2732                w.html(tc.toString());
  • trunk/wp-includes/script-loader.php

    r19897 r19966  
    279279
    280280    $scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array( 'jquery' ), false, 1 );
     281    $scripts->localize( 'word-count', 'wordCountL10n', array(
     282        /* translators: If your word count is based on single characters (East Asian characters),
     283           enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */
     284        'type' => 'characters' == _x( 'words', 'word count: words or characters?' ) ? 'c' : 'w',
     285    ) );
    281286
    282287    $scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox' ), false, 1 );
Note: See TracChangeset for help on using the changeset viewer.