Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/trunk' into html-api/add-input…
Browse files Browse the repository at this point in the history
…-tag-handling
  • Loading branch information
dmsnell committed Jan 24, 2024
2 parents fee724f + 86d4ac2 commit dbf9831
Show file tree
Hide file tree
Showing 50 changed files with 2,749 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/wp-admin/includes/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@ function delete_plugins( $plugins, $deprecated = '' ) {
foreach ( $translations as $translation => $data ) {
$wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.po' );
$wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.mo' );
$wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.l10n.php' );

$json_translation_files = glob( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '-*.json' );
if ( $json_translation_files ) {
Expand Down
1 change: 1 addition & 0 deletions src/wp-content/themes/twentytwentytwo/theme.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 2,
"customTemplates": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-comment-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public function __construct( $query = '' ) {
*
* @since 4.2.0 Extracted from WP_Comment_Query::query().
*
* @param string|array $query WP_Comment_Query arguments. See WP_Comment_Query::__construct()
* @param string|array $query WP_Comment_Query arguments. See WP_Comment_Query::__construct().
*/
public function parse_query( $query = '' ) {
if ( empty( $query ) ) {
Expand Down
2 changes: 2 additions & 0 deletions src/wp-includes/class-wp-locale-switcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ private function change_locale( $locale ) {

$wp_locale = new WP_Locale();

WP_Translation_Controller::instance()->set_locale( $locale );

/**
* Fires when the locale is switched to or restored.
*
Expand Down
1 change: 1 addition & 0 deletions src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,7 @@ public function get_stylesheet( $types = array( 'variables', 'styles', 'presets'
foreach ( $style_nodes as &$node ) {
$node['selector'] = static::scope_selector( $options['scope'], $node['selector'] );
}
unset( $node );
}

if ( ! empty( $options['root_selector'] ) ) {
Expand Down
32 changes: 32 additions & 0 deletions src/wp-includes/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,38 @@ function array_key_last( array $array ) { // phpcs:ignore Universal.NamingConven
}
}

if ( ! function_exists( 'array_is_list' ) ) {
/**
* Polyfill for `array_is_list()` function added in PHP 8.1.
*
* Determines if the given array is a list.
*
* An array is considered a list if its keys consist of consecutive numbers from 0 to count($array)-1.
*
* @see https://github.com/symfony/polyfill-php81/tree/main
*
* @since 6.5.0
*
* @param array<mixed> $arr The array being evaluated.
* @return bool True if array is a list, false otherwise.
*/
function array_is_list( $arr ) {
if ( ( array() === $arr ) || ( array_values( $arr ) === $arr ) ) {
return true;
}

$next_key = -1;

foreach ( $arr as $k => $v ) {
if ( ++$next_key !== $k ) {
return false;
}
}

return true;
}
}

if ( ! function_exists( 'str_contains' ) ) {
/**
* Polyfill for `str_contains()` function added in PHP 8.0.
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6550,7 +6550,7 @@ function wp_timezone_choice( $selected_zone, $locale = null ) {
if ( ! $mo_loaded || $locale !== $locale_loaded ) {
$locale_loaded = $locale ? $locale : get_locale();
$mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
unload_textdomain( 'continents-cities' );
unload_textdomain( 'continents-cities', true );
load_textdomain( 'continents-cities', $mofile, $locale_loaded );
$mo_loaded = true;
}
Expand Down
68 changes: 58 additions & 10 deletions src/wp-includes/l10n.php
Original file line number Diff line number Diff line change
Expand Up @@ -797,22 +797,65 @@ function load_textdomain( $domain, $mofile, $locale = null ) {
$locale = determine_locale();
}

$mo = new MO();
if ( ! $mo->import_from_file( $mofile ) ) {
$wp_textdomain_registry->set( $domain, $locale, false );
$i18n_controller = WP_Translation_Controller::instance();

return false;
// Ensures the correct locale is set as the current one, in case it was filtered.
$i18n_controller->set_locale( $locale );

/**
* Filters the preferred file format for translation files.
*
* Can be used to disable the use of PHP files for translations.
*
* @since 6.5.0
*
* @param string $preferred_format Preferred file format. Possible values: 'php', 'mo'. Default: 'php'.
* @param string $domain The text domain.
*/
$preferred_format = apply_filters( 'translation_file_format', 'php', $domain );
if ( ! in_array( $preferred_format, array( 'php', 'mo' ), true ) ) {
$preferred_format = 'php';
}

if ( isset( $l10n[ $domain ] ) ) {
$mo->merge_with( $l10n[ $domain ] );
$translation_files = array( $mofile );
if ( 'mo' !== $preferred_format ) {
array_unshift(
$translation_files,
substr_replace( $mofile, ".l10n.$preferred_format", - strlen( '.mo' ) )
);
}

unset( $l10n_unloaded[ $domain ] );
foreach ( $translation_files as $file ) {
/**
* Filters the file path for loading translations for the given text domain.
*
* Similar to the {@see 'load_textdomain_mofile'} filter with the difference that
* the file path could be for an MO or PHP file.
*
* @since 6.5.0
*
* @param string $file Path to the translation file to load.
* @param string $domain The text domain.
*/
$file = (string) apply_filters( 'load_translation_file', $file, $domain );

$success = $i18n_controller->load_file( $file, $domain, $locale );

if ( $success ) {
if ( isset( $l10n[ $domain ] ) && $l10n[ $domain ] instanceof MO ) {
$i18n_controller->load_file( $l10n[ $domain ]->get_filename(), $domain, $locale );
}

// Unset NOOP_Translations reference in get_translations_for_domain().
unset( $l10n[ $domain ] );

$l10n[ $domain ] = new WP_Translations( $i18n_controller, $domain );

$l10n[ $domain ] = &$mo;
$wp_textdomain_registry->set( $domain, $locale, dirname( $file ) );

$wp_textdomain_registry->set( $domain, $locale, dirname( $mofile ) );
return true;
}
}

return true;
}
Expand Down Expand Up @@ -866,6 +909,11 @@ function unload_textdomain( $domain, $reloadable = false ) {
*/
do_action( 'unload_textdomain', $domain, $reloadable );

// Since multiple locales are supported, reloadable text domains don't actually need to be unloaded.
if ( ! $reloadable ) {
WP_Translation_Controller::instance()->unload_textdomain( $domain );
}

if ( isset( $l10n[ $domain ] ) ) {
if ( $l10n[ $domain ] instanceof NOOP_Translations ) {
unset( $l10n[ $domain ] );
Expand Down Expand Up @@ -904,7 +952,7 @@ function load_default_textdomain( $locale = null ) {
}

// Unload previously loaded strings so we can switch translations.
unload_textdomain( 'default' );
unload_textdomain( 'default', true );

$return = load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo", $locale );

Expand Down
Loading

0 comments on commit dbf9831

Please sign in to comment.