Make WordPress Core


Ignore:
Timestamp:
06/08/2019 06:41:08 PM (5 years ago)
Author:
johnbillion
Message:

I18N: Allow the length of automatically generated excerpts to be localized.

This introduces three new strings that can be used to control the maximum length of automatically generated excerpts for posts, comments, and draft post previews in the dashboard. Optionally combined with the existing word count type control this allows languages which include many multibyte characters to specify more appropriate maximum excerpt lengths.

Props miyauchi, birgire, johnbillion

Fixes #44541

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/WPTrimWords.php

    r42343 r45505  
    55 */
    66class Tests_Formatting_WPTrimWords extends WP_UnitTestCase {
     7
     8    /**
     9     * Long Dummy Text.
     10     *
     11     * @since 5.0.0
     12     *
     13     * @var string $long_text
     14     */
    715    private $long_text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce varius lacinia vehicula. Etiam sapien risus, ultricies ac posuere eu, convallis sit amet augue. Pellentesque urna massa, lacinia vel iaculis eget, bibendum in mauris. Aenean eleifend pulvinar ligula, a convallis eros gravida non. Suspendisse potenti. Pellentesque et odio tortor. In vulputate pellentesque libero, sed dapibus velit mollis viverra. Pellentesque id urna euismod dolor cursus sagittis.';
    816
     
    4351        $this->assertEquals( $text, wp_trim_words( $text ) );
    4452    }
     53
     54    /**
     55     * @ticket 44541
     56     */
     57    function test_trims_to_20_counted_by_chars() {
     58        switch_to_locale( 'ja_JP' );
     59        $expected = substr( $this->long_text, 0, 20 ) . '…';
     60        $actual   = wp_trim_words( $this->long_text, 20 );
     61        restore_previous_locale();
     62        $this->assertEquals( $expected, $actual );
     63    }
     64
     65    /**
     66     * @ticket 44541
     67     */
     68    function test_trims_to_20_counted_by_chars_with_double_width_chars() {
     69        switch_to_locale( 'ja_JP' );
     70        $text     = str_repeat( 'あ', 100 );
     71        $expected = str_repeat( 'あ', 19 ) . '…';
     72        $actual   = wp_trim_words( $text, 19 );
     73        restore_previous_locale();
     74        $this->assertEquals( $expected, $actual );
     75    }
    4576}
Note: See TracChangeset for help on using the changeset viewer.