i18n: Define List item separator as a WP_Locale property.

The list item separator is a locale property, and it doesn't make much sense to translate it separately in multiple projects. This changeset implements the following modifications:

- Define list item separator as a new WP_Locale property
- Add `wp_get_list_item_separator()` as a wrapper for `WP_Locale::get_list_item_separator`
- Replace `$wp_locale->get_list_item_separator()` calls with `wp_get_list_item_separator()`
- Added a compatibility layer for bundled themes

Props SergeyBiryukov, swissspidy, rsiddharth, johnbillion, audrasjb.
Fixes #39733.

Built from https://develop.svn.wordpress.org/trunk@52929


git-svn-id: http://core.svn.wordpress.org/trunk@52518 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
audrasjb 2022-03-13 20:03:01 +00:00
parent 3046b5b3e1
commit 30a77d5fa4
21 changed files with 147 additions and 53 deletions

View File

@ -633,8 +633,7 @@ class WP_Media_List_Table extends WP_List_Table {
esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
);
}
/* translators: Used between list items, there is a space after the comma. */
echo implode( __( ', ' ), $out );
echo implode( wp_get_list_item_separator(), $out );
} else {
echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . get_taxonomy( $taxonomy )->labels->no_terms . '</span>';
}

View File

@ -1294,8 +1294,7 @@ class WP_Posts_List_Table extends WP_List_Table {
*/
$term_links = apply_filters( 'post_column_taxonomy_links', $term_links, $taxonomy, $terms );
/* translators: Used between list items, there is a space after the comma. */
echo implode( __( ', ' ), $term_links );
echo implode( wp_get_list_item_separator(), $term_links );
} else {
echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>';
}

View File

@ -32,8 +32,7 @@ global $feature_class;
<footer class="entry-meta">
<?php
/* translators: Used between list items, there is a space after the comma. */
$tags_list = get_the_tag_list( '', __( ', ', 'twentyeleven' ) );
$tags_list = get_the_tag_list( '', wp_get_list_item_separator() );
if ( $tags_list && ! is_wp_error( $tags_list ) ) {
/* translators: 1: Category list, 2: Tag list, 3: Post permalink, 4: Post title. */
@ -45,8 +44,7 @@ global $feature_class;
printf(
$utility_text,
/* translators: Used between list items, there is a space after the comma. */
get_the_category_list( __( ', ', 'twentyeleven' ) ),
get_the_category_list( wp_get_list_item_separator() ),
$tags_list,
esc_url( get_permalink() ),
the_title_attribute( 'echo=0' )

View File

@ -72,8 +72,7 @@
<?php $show_sep = false; ?>
<?php
/* translators: Used between list items, there is a space after the comma. */
$categories_list = get_the_category_list( __( ', ', 'twentyeleven' ) );
$categories_list = get_the_category_list( wp_get_list_item_separator() );
if ( $categories_list ) :
?>
@ -87,8 +86,7 @@
<?php endif; // End if categories. ?>
<?php
/* translators: Used between list items, there is a space after the comma. */
$tags_list = get_the_tag_list( '', __( ', ', 'twentyeleven' ) );
$tags_list = get_the_tag_list( '', wp_get_list_item_separator() );
if ( $tags_list && ! is_wp_error( $tags_list ) ) :
if ( $show_sep ) :

View File

@ -55,8 +55,7 @@
</div><!-- .entry-meta -->
<div class="entry-meta">
<?php
/* translators: Used between list items, there is a space after the comma. */
$categories_list = get_the_category_list( __( ', ', 'twentyeleven' ) );
$categories_list = get_the_category_list( wp_get_list_item_separator() );
if ( $categories_list ) :
?>
@ -69,8 +68,7 @@
<?php endif; // End if categories. ?>
<?php
/* translators: Used between list items, there is a space after the comma. */
$tags_list = get_the_tag_list( '', __( ', ', 'twentyeleven' ) );
$tags_list = get_the_tag_list( '', wp_get_list_item_separator() );
if ( $tags_list && ! is_wp_error( $tags_list ) ) :
?>

View File

@ -48,8 +48,7 @@
<?php $show_sep = false; ?>
<?php
/* translators: Used between list items, there is a space after the comma. */
$categories_list = get_the_category_list( __( ', ', 'twentyeleven' ) );
$categories_list = get_the_category_list( wp_get_list_item_separator() );
if ( $categories_list ) :
?>
@ -63,8 +62,7 @@
<?php endif; // End if categories. ?>
<?php
/* translators: Used between list items, there is a space after the comma. */
$tags_list = get_the_tag_list( '', __( ', ', 'twentyeleven' ) );
$tags_list = get_the_tag_list( '', wp_get_list_item_separator() );
if ( $tags_list && ! is_wp_error( $tags_list ) ) :
if ( $show_sep ) :

View File

@ -33,11 +33,9 @@
<footer class="entry-meta">
<?php
/* translators: Used between list items, there is a space after the comma. */
$categories_list = get_the_category_list( __( ', ', 'twentyeleven' ) );
$categories_list = get_the_category_list( wp_get_list_item_separator() );
/* translators: Used between list items, there is a space after the comma. */
$tags_list = get_the_tag_list( '', __( ', ', 'twentyeleven' ) );
$tags_list = get_the_tag_list( '', wp_get_list_item_separator() );
if ( $tags_list && ! is_wp_error( $tags_list ) ) {
/* translators: 1: Categories list, 2: Tag list, 3: Permalink, 4: Post title, 5: Author name, 6: Author URL. */

View File

@ -55,8 +55,7 @@
<?php if ( is_object_in_taxonomy( get_post_type(), 'category' ) ) : // Hide category text when not supported. ?>
<?php
/* translators: Used between list items, there is a space after the comma. */
$categories_list = get_the_category_list( __( ', ', 'twentyeleven' ) );
$categories_list = get_the_category_list( wp_get_list_item_separator() );
if ( $categories_list ) :
?>
@ -72,8 +71,7 @@
<?php if ( is_object_in_taxonomy( get_post_type(), 'post_tag' ) ) : // Hide tag text when not supported. ?>
<?php
/* translators: Used between list items, there is a space after the comma. */
$tags_list = get_the_tag_list( '', __( ', ', 'twentyeleven' ) );
$tags_list = get_the_tag_list( '', wp_get_list_item_separator() );
if ( $tags_list && ! is_wp_error( $tags_list ) ) :
if ( $show_sep ) :

View File

@ -929,3 +929,17 @@ function twentyeleven_skip_link() {
}
}
add_action( 'wp_body_open', 'twentyeleven_skip_link', 5 );
if ( ! function_exists( 'wp_get_list_item_separator' ) ) :
/**
* Retrieves the list item separator based on the locale.
*
* Added for backward compatibility to support pre-6.0.0 WordPress versions.
*
* @since 6.0.0
*/
function wp_get_list_item_separator() {
/* translators: Used between list items, there is a space after the comma. */
return __( ', ', 'twentyeleven' );
}
endif;

View File

@ -182,6 +182,20 @@ if ( ! function_exists( 'twentynineteen_setup' ) ) :
endif;
add_action( 'after_setup_theme', 'twentynineteen_setup' );
if ( ! function_exists( 'wp_get_list_item_separator' ) ) :
/**
* Retrieves the list item separator based on the locale.
*
* Added for backward compatibility to support pre-6.0.0 WordPress versions.
*
* @since 6.0.0
*/
function wp_get_list_item_separator() {
/* translators: Used between list items, there is a space after the comma. */
return __( ', ', 'twentynineteen' );
}
endif;
/**
* Register widget area.
*

View File

@ -82,8 +82,7 @@ if ( ! function_exists( 'twentynineteen_entry_footer' ) ) :
// Posted on.
twentynineteen_posted_on();
/* translators: Used between list items, there is a space after the comma. */
$categories_list = get_the_category_list( __( ', ', 'twentynineteen' ) );
$categories_list = get_the_category_list( wp_get_list_item_separator() );
if ( $categories_list ) {
printf(
/* translators: 1: SVG icon. 2: Posted in label, only visible to screen readers. 3: List of categories. */
@ -94,8 +93,7 @@ if ( ! function_exists( 'twentynineteen_entry_footer' ) ) :
); // WPCS: XSS OK.
}
/* translators: Used between list items, there is a space after the comma. */
$tags_list = get_the_tag_list( '', __( ', ', 'twentynineteen' ) );
$tags_list = get_the_tag_list( '', wp_get_list_item_separator() );
if ( $tags_list && ! is_wp_error( $tags_list ) ) {
printf(
/* translators: 1: SVG icon. 2: Posted in label, only visible to screen readers. 3: List of tags. */

View File

@ -647,6 +647,20 @@ function twentyseventeen_unique_id( $prefix = '' ) {
return $prefix . (string) ++$id_counter;
}
if ( ! function_exists( 'wp_get_list_item_separator' ) ) :
/**
* Retrieves the list item separator based on the locale.
*
* Added for backward compatibility to support pre-6.0.0 WordPress versions.
*
* @since 6.0.0
*/
function wp_get_list_item_separator() {
/* translators: Used between list items, there is a space after the comma. */
return __( ', ', 'twentyseventeen' );
}
endif;
/**
* Implement the Custom Header feature.
*/

View File

@ -62,8 +62,7 @@ if ( ! function_exists( 'twentyseventeen_entry_footer' ) ) :
*/
function twentyseventeen_entry_footer() {
/* translators: Used between list items, there is a space after the comma. */
$separate_meta = __( ', ', 'twentyseventeen' );
$separate_meta = wp_get_list_item_separator();
// Get Categories for posts.
$categories_list = get_the_category_list( $separate_meta );

View File

@ -438,6 +438,20 @@ function twentythirteen_widgets_init() {
}
add_action( 'widgets_init', 'twentythirteen_widgets_init' );
if ( ! function_exists( 'wp_get_list_item_separator' ) ) :
/**
* Retrieves the list item separator based on the locale.
*
* Added for backward compatibility to support pre-6.0.0 WordPress versions.
*
* @since 6.0.0
*/
function wp_get_list_item_separator() {
/* translators: Used between list items, there is a space after the comma. */
return __( ', ', 'twentythirteen' );
}
endif;
if ( ! function_exists( 'twentythirteen_paging_nav' ) ) :
/**
* Display navigation to next/previous set of posts when applicable.
@ -517,14 +531,12 @@ if ( ! function_exists( 'twentythirteen_entry_meta' ) ) :
twentythirteen_entry_date();
}
/* translators: Used between list items, there is a space after the comma. */
$categories_list = get_the_category_list( __( ', ', 'twentythirteen' ) );
$categories_list = get_the_category_list( wp_get_list_item_separator() );
if ( $categories_list ) {
echo '<span class="categories-links">' . $categories_list . '</span>';
}
/* translators: Used between list items, there is a space after the comma. */
$tags_list = get_the_tag_list( '', __( ', ', 'twentythirteen' ) );
$tags_list = get_the_tag_list( '', wp_get_list_item_separator() );
if ( $tags_list && ! is_wp_error( $tags_list ) ) {
echo '<span class="tags-links">' . $tags_list . '</span>';
}

View File

@ -384,6 +384,20 @@ function twentytwelve_widgets_init() {
}
add_action( 'widgets_init', 'twentytwelve_widgets_init' );
if ( ! function_exists( 'wp_get_list_item_separator' ) ) :
/**
* Retrieves the list item separator based on the locale.
*
* Added for backward compatibility to support pre-6.0.0 WordPress versions.
*
* @since 6.0.0
*/
function wp_get_list_item_separator() {
/* translators: Used between list items, there is a space after the comma. */
return __( ', ', 'twentytwelve' );
}
endif;
if ( ! function_exists( 'twentytwelve_content_nav' ) ) :
/**
* Displays navigation to next/previous pages when applicable.
@ -502,11 +516,9 @@ if ( ! function_exists( 'twentytwelve_entry_meta' ) ) :
* @since Twenty Twelve 1.0
*/
function twentytwelve_entry_meta() {
/* translators: Used between list items, there is a space after the comma. */
$categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
$categories_list = get_the_category_list( wp_get_list_item_separator() );
/* translators: Used between list items, there is a space after the comma. */
$tags_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );
$tags_list = get_the_tag_list( '', wp_get_list_item_separator() );
$date = sprintf(
'<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>',

View File

@ -640,3 +640,17 @@ function twentytwentyone_add_ie_class() {
<?php
}
add_action( 'wp_footer', 'twentytwentyone_add_ie_class' );
if ( ! function_exists( 'wp_get_list_item_separator' ) ) :
/**
* Retrieves the list item separator based on the locale.
*
* Added for backward compatibility to support pre-6.0.0 WordPress versions.
*
* @since 6.0.0
*/
function wp_get_list_item_separator() {
/* translators: Used between list items, there is a space after the comma. */
return __( ', ', 'twentytwentyone' );
}
endif;

View File

@ -100,8 +100,7 @@ if ( ! function_exists( 'twenty_twenty_one_entry_meta_footer' ) ) {
echo '<div class="post-taxonomies">';
/* translators: Used between list items, there is a space after the comma. */
$categories_list = get_the_category_list( __( ', ', 'twentytwentyone' ) );
$categories_list = get_the_category_list( wp_get_list_item_separator() );
if ( $categories_list ) {
printf(
/* translators: %s: List of categories. */
@ -110,8 +109,7 @@ if ( ! function_exists( 'twenty_twenty_one_entry_meta_footer' ) ) {
);
}
/* translators: Used between list items, there is a space after the comma. */
$tags_list = get_the_tag_list( '', __( ', ', 'twentytwentyone' ) );
$tags_list = get_the_tag_list( '', wp_get_list_item_separator() );
if ( $tags_list ) {
printf(
/* translators: %s: List of tags. */
@ -144,8 +142,7 @@ if ( ! function_exists( 'twenty_twenty_one_entry_meta_footer' ) ) {
echo '<div class="post-taxonomies">';
/* translators: Used between list items, there is a space after the comma. */
$categories_list = get_the_category_list( __( ', ', 'twentytwentyone' ) );
$categories_list = get_the_category_list( wp_get_list_item_separator() );
if ( $categories_list ) {
printf(
/* translators: %s: List of categories. */
@ -154,8 +151,7 @@ if ( ! function_exists( 'twenty_twenty_one_entry_meta_footer' ) ) {
);
}
/* translators: Used between list items, there is a space after the comma. */
$tags_list = get_the_tag_list( '', __( ', ', 'twentytwentyone' ) );
$tags_list = get_the_tag_list( '', wp_get_list_item_separator() );
if ( $tags_list ) {
printf(
/* translators: %s: List of tags. */

View File

@ -95,6 +95,14 @@ class WP_Locale {
*/
public $number_format;
/**
* The separator string used for localizing list item separator.
*
* @since 6.0.0
* @var string
*/
public $list_item_separator;
/**
* Constructor which calls helper methods to set up object variables.
*
@ -209,6 +217,9 @@ class WP_Locale {
$this->number_format['decimal_point'] = ( 'number_format_decimal_point' === $decimal_point ) ? '.' : $decimal_point;
/* translators: used between list items, there is a space after the comma */
$this->list_item_separator = __( ', ' );
// Set text direction.
if ( isset( $GLOBALS['text_direction'] ) ) {
$this->text_direction = $GLOBALS['text_direction'];
@ -366,4 +377,15 @@ class WP_Locale {
/* translators: Localized date and time format, see https://www.php.net/manual/datetime.format.php */
__( 'F j, Y g:i a' );
}
/**
* Retrieve the localized list item separator.
*
* @since 6.0.0
*
* @return string Localized list item separator.
*/
public function get_list_item_separator() {
return $this->list_item_separator;
}
}

View File

@ -924,8 +924,7 @@ final class WP_Theme implements ArrayAccess {
case 'Tags':
static $comma = null;
if ( ! isset( $comma ) ) {
/* translators: Used between list items, there is a space after the comma. */
$comma = __( ', ' );
$comma = wp_get_list_item_separator();
}
$value = implode( $comma, $value );
break;

View File

@ -8371,3 +8371,17 @@ function is_php_version_compatible( $required ) {
function wp_fuzzy_number_match( $expected, $actual, $precision = 1 ) {
return abs( (float) $expected - (float) $actual ) <= $precision;
}
/**
* Retrieves the list item separator based on the locale.
*
* @since 6.0.0
*
* @global WP_Locale $wp_locale WordPress date and time locale object.
*
* @return string Locale specific list item separator.
*/
function wp_get_list_item_separator() {
global $wp_locale;
return $wp_locale->get_list_item_separator();
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.0-alpha-52928';
$wp_version = '6.0-alpha-52929';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.