I18N: Change how WP_Textdomain_Registry stores the default languages path.

`WP_Textdomain_Registry` was introduced in [53874] to store text domains and their language directory paths, addressing issues with just-in-time loading of textdomains when using locale switching and when using`load_*_textdomain()` functions.

Said change has inadvertently caused a performance regression exactly when using`load_*_textdomain()`, which still often is the case, where the cached information was not further used or even overridden.

This change addresses that issue by storing the default languages paths in a separate way, while at the same time making `WP_Textdomain_Registry` easier to maintain and adding new tests to catch future regressions.

Props flixos90, spacedmonkey, ocean90, SergeyBiryukov, costdev.
Fixes #39210.

git-svn-id: https://develop.svn.wordpress.org/trunk@54669 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler
2022-10-24 10:01:01 +00:00
parent a5463b4500
commit 799d7dc86f
6 changed files with 258 additions and 88 deletions
+4 -4
View File
@@ -934,7 +934,7 @@ function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path
$path = WP_PLUGIN_DIR;
}
$wp_textdomain_registry->set( $domain, $locale, $path );
$wp_textdomain_registry->set_custom_path( $domain, $path );
return load_textdomain( $domain, $path . '/' . $mofile, $locale );
}
@@ -968,7 +968,7 @@ function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) {
$path = WPMU_PLUGIN_DIR . '/' . ltrim( $mu_plugin_rel_path, '/' );
$wp_textdomain_registry->set( $domain, $locale, $path );
$wp_textdomain_registry->set_custom_path( $domain, $path );
return load_textdomain( $domain, $path . '/' . $mofile, $locale );
}
@@ -1016,7 +1016,7 @@ function load_theme_textdomain( $domain, $path = false ) {
$path = get_template_directory();
}
$wp_textdomain_registry->set( $domain, $locale, $path );
$wp_textdomain_registry->set_custom_path( $domain, $path );
return load_textdomain( $domain, $path . '/' . $locale . '.mo', $locale );
}
@@ -1265,7 +1265,7 @@ function _load_textdomain_just_in_time( $domain ) {
return false;
}
if ( $wp_textdomain_registry->has( $domain ) && ! $wp_textdomain_registry->get_current( $domain ) ) {
if ( ! $wp_textdomain_registry->has( $domain ) ) {
return false;
}