Skip to content

Commit

Permalink
Use new function wp_get_word_count_type()
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed Feb 11, 2023
1 parent 3971188 commit 74cbb73
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
32 changes: 32 additions & 0 deletions lib/experimental/l10n.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* PHP and WordPress configuration compatibility functions for the Gutenberg
* editor plugin changes related to i18n.
*
* @package gutenberg
*/

/**
* Override core's wp_get_word_count_type() introduced in WordPress 6.2.
* Originally, get_word_count_type() method of the WP_Locale class is executed,
* but the process is simulated here.
*
* This function should not be backported to core.
*/
if ( ! function_exists( 'wp_get_word_count_type' ) ) {
/**
* Retrieves the word count type based on the locale.
*
* @return string Locale-specific word count type.
*/
function wp_get_word_count_type() {
$word_count_type = _x( 'words', 'Word count type. Do not translate!', 'gutenberg' );

// Check for valid types.
if ( 'characters_excluding_spaces' !== $word_count_type && 'characters_including_spaces' !== $word_count_type ) {
// Defaults to 'words'.
$word_count_type = 'words';
}
return $word_count_type;
}
}
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/experimental/navigation-theme-opt-in.php';
require __DIR__ . '/experimental/kses.php';
require __DIR__ . '/experimental/formatting.php';
require __DIR__ . '/experimental/l10n.php';

// Fonts API.
require __DIR__ . '/experimental/fonts-api/class-wp-fonts-provider.php';
Expand Down
7 changes: 1 addition & 6 deletions packages/block-library/src/post-time-to-read/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ function render_block_core_post_time_to_read( $attributes, $content, $block ) {
*/
$average_reading_rate = 189;

/*
* translators: If your word count is based on single characters (e.g. East Asian characters),
* enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
* Do not translate into your own language.
*/
$word_count_type = _x( 'words', 'Word count type. Do not translate!' );
$word_count_type = wp_get_word_count_type();

$minutes_to_read = max( 1, (int) round( wp_word_count( $content, $word_count_type ) / $average_reading_rate ) );

Expand Down

0 comments on commit 74cbb73

Please sign in to comment.