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. git-svn-id: http://core.svn.wordpress.org/trunk@20859 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
397fc6f8c9
commit
b36c335b7a
|
@ -2127,6 +2127,10 @@ function wp_trim_excerpt($text = '') {
|
||||||
/**
|
/**
|
||||||
* Trims text to a certain number of words.
|
* Trims text to a certain number of words.
|
||||||
*
|
*
|
||||||
|
* This function is localized. For languages that count 'words' by the individual
|
||||||
|
* character (such as East Asian languages), the $num_words argument will apply
|
||||||
|
* to the number of individual characters.
|
||||||
|
*
|
||||||
* @since 3.3.0
|
* @since 3.3.0
|
||||||
*
|
*
|
||||||
* @param string $text Text to trim.
|
* @param string $text Text to trim.
|
||||||
|
@ -2139,13 +2143,23 @@ function wp_trim_words( $text, $num_words = 55, $more = null ) {
|
||||||
$more = __( '…' );
|
$more = __( '…' );
|
||||||
$original_text = $text;
|
$original_text = $text;
|
||||||
$text = wp_strip_all_tags( $text );
|
$text = wp_strip_all_tags( $text );
|
||||||
$words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY );
|
/* translators: If your word count is based on single characters (East Asian characters),
|
||||||
|
enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */
|
||||||
|
if ( 'characters' == _x( 'words', 'word count: words or characters?' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) {
|
||||||
|
$text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
|
||||||
|
preg_match_all( '/./u', $text, $words_array );
|
||||||
|
$words_array = array_slice( $words_array[0], 0, $num_words + 1 );
|
||||||
|
$sep = '';
|
||||||
|
} else {
|
||||||
|
$words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY );
|
||||||
|
$sep = ' ';
|
||||||
|
}
|
||||||
if ( count( $words_array ) > $num_words ) {
|
if ( count( $words_array ) > $num_words ) {
|
||||||
array_pop( $words_array );
|
array_pop( $words_array );
|
||||||
$text = implode( ' ', $words_array );
|
$text = implode( $sep, $words_array );
|
||||||
$text = $text . $more;
|
$text = $text . $more;
|
||||||
} else {
|
} else {
|
||||||
$text = implode( ' ', $words_array );
|
$text = implode( $sep, $words_array );
|
||||||
}
|
}
|
||||||
return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text );
|
return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue