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.


git-svn-id: https://develop.svn.wordpress.org/trunk@52929 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jb Audras
2022-03-13 20:01:05 +00:00
parent 89de8f3b35
commit a37a72077e
20 changed files with 146 additions and 52 deletions
+22
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;
}
}
+1 -2
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;
+14
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();
}