Fixing WordPress Excerpts Word Count in Chinese

Some users reported that the WordPress excerpts word count is incorrect in Chinese. This PHP snippet should help:

function dez_filter_chinese_excerpt( $output ) {
    global $post;
    //check if its chinese character input
    $chinese_output = preg_match_all("/\p{Han}+/u", $post->post_content, $matches);
    if($chinese_output) {
        $output = sprintf( '%1$s <p class="read-more-button-container"><a class="button" href="%2$s">%3$s</a></p>',
            mb_substr( $output, 0, 50 ) . '...',
            get_permalink(),
            __( 'Read more', 'generatepress' )
        );
    }
    return $output;
}
add_filter( 'get_the_excerpt', 'dez_filter_chinese_excerpt' );