WordPress.org

Make WordPress Core

Changeset 20859


Ignore:
Timestamp:
05/23/2012 09:04:35 PM (6 years ago)
Author:
westi
Message:

i18n: Update the word splitting we use when trimming strings to build excerpts so that it has support for a character based mode for locales where character splitting is more approproate like Japan.

See #16079 props tenpura.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/formatting.php

    r20687 r20859  
    21282128 * Trims text to a certain number of words.
    21292129 *
     2130 * This function is localized. For languages that count 'words' by the individual
     2131 * character (such as East Asian languages), the $num_words argument will apply
     2132 * to the number of individual characters.
     2133 *
    21302134 * @since 3.3.0
    21312135 *
     
    21402144    $original_text = $text;
    21412145    $text = wp_strip_all_tags( $text );
    2142     $words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY );
     2146    /* translators: If your word count is based on single characters (East Asian characters),
     2147       enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */
     2148    if ( 'characters' == _x( 'words', 'word count: words or characters?' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) {
     2149        $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
     2150        preg_match_all( '/./u', $text, $words_array );
     2151        $words_array = array_slice( $words_array[0], 0, $num_words + 1 );
     2152        $sep = '';
     2153    } else {
     2154        $words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY );
     2155        $sep = ' ';
     2156    }
    21432157    if ( count( $words_array ) > $num_words ) {
    21442158        array_pop( $words_array );
    2145         $text = implode( ' ', $words_array );
     2159        $text = implode( $sep, $words_array );
    21462160        $text = $text . $more;
    21472161    } else {
    2148         $text = implode( ' ', $words_array );
     2162        $text = implode( $sep, $words_array );
    21492163    }
    21502164    return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text );
Note: See TracChangeset for help on using the changeset viewer.