rebase on oct-10-2023
This commit is contained in:
@@ -132,30 +132,28 @@ function determine_locale() {
|
||||
*/
|
||||
$determined_locale = apply_filters( 'pre_determine_locale', null );
|
||||
|
||||
if ( ! empty( $determined_locale ) && is_string( $determined_locale ) ) {
|
||||
if ( $determined_locale && is_string( $determined_locale ) ) {
|
||||
return $determined_locale;
|
||||
}
|
||||
|
||||
$determined_locale = get_locale();
|
||||
|
||||
if ( is_admin() ) {
|
||||
if (
|
||||
isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] &&
|
||||
( ! empty( $_GET['wp_lang'] ) || ! empty( $_COOKIE['wp_lang'] ) )
|
||||
) {
|
||||
if ( ! empty( $_GET['wp_lang'] ) ) {
|
||||
$determined_locale = sanitize_locale_name( $_GET['wp_lang'] );
|
||||
} else {
|
||||
$determined_locale = sanitize_locale_name( $_COOKIE['wp_lang'] );
|
||||
}
|
||||
} elseif (
|
||||
is_admin() ||
|
||||
( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() )
|
||||
) {
|
||||
$determined_locale = get_user_locale();
|
||||
}
|
||||
|
||||
if ( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() ) {
|
||||
$determined_locale = get_user_locale();
|
||||
}
|
||||
|
||||
$wp_lang = '';
|
||||
|
||||
if ( ! empty( $_GET['wp_lang'] ) ) {
|
||||
$wp_lang = sanitize_locale_name( wp_unslash( $_GET['wp_lang'] ) );
|
||||
} elseif ( ! empty( $_COOKIE['wp_lang'] ) ) {
|
||||
$wp_lang = sanitize_locale_name( wp_unslash( $_COOKIE['wp_lang'] ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $wp_lang ) && ! empty( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
|
||||
$determined_locale = $wp_lang;
|
||||
if ( ! $determined_locale ) {
|
||||
$determined_locale = get_locale();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -721,6 +719,28 @@ function load_textdomain( $domain, $mofile, $locale = null ) {
|
||||
|
||||
$l10n_unloaded = (array) $l10n_unloaded;
|
||||
|
||||
/**
|
||||
* Filters whether to short-circuit loading .mo file.
|
||||
*
|
||||
* Returning a non-null value from the filter will effectively short-circuit
|
||||
* the loading, returning the passed value instead.
|
||||
*
|
||||
* @since 6.3.0
|
||||
*
|
||||
* @param bool|null $loaded The result of loading a .mo file. Default null.
|
||||
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
|
||||
* @param string $mofile Path to the MO file.
|
||||
* @param string|null $locale Locale.
|
||||
*/
|
||||
$loaded = apply_filters( 'pre_load_textdomain', null, $domain, $mofile, $locale );
|
||||
if ( null !== $loaded ) {
|
||||
if ( true === $loaded ) {
|
||||
unset( $l10n_unloaded[ $domain ] );
|
||||
}
|
||||
|
||||
return $loaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters whether to override the .mo file loading.
|
||||
*
|
||||
@@ -838,6 +858,12 @@ function unload_textdomain( $domain, $reloadable = false ) {
|
||||
do_action( 'unload_textdomain', $domain, $reloadable );
|
||||
|
||||
if ( isset( $l10n[ $domain ] ) ) {
|
||||
if ( $l10n[ $domain ] instanceof NOOP_Translations ) {
|
||||
unset( $l10n[ $domain ] );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
unset( $l10n[ $domain ] );
|
||||
|
||||
if ( ! $reloadable ) {
|
||||
@@ -1084,7 +1110,7 @@ function load_script_textdomain( $handle, $domain = 'default', $path = '' ) {
|
||||
|
||||
$src = $wp_scripts->registered[ $handle ]->src;
|
||||
|
||||
if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $wp_scripts->content_url && 0 === strpos( $src, $wp_scripts->content_url ) ) ) {
|
||||
if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $wp_scripts->content_url && str_starts_with( $src, $wp_scripts->content_url ) ) ) {
|
||||
$src = $wp_scripts->base_url . $src;
|
||||
}
|
||||
|
||||
@@ -1098,7 +1124,7 @@ function load_script_textdomain( $handle, $domain = 'default', $path = '' ) {
|
||||
|
||||
// If the host is the same or it's a relative URL.
|
||||
if (
|
||||
( ! isset( $content_url['path'] ) || strpos( $src_url['path'], $content_url['path'] ) === 0 ) &&
|
||||
( ! isset( $content_url['path'] ) || str_starts_with( $src_url['path'], $content_url['path'] ) ) &&
|
||||
( ! isset( $src_url['host'] ) || ! isset( $content_url['host'] ) || $src_url['host'] === $content_url['host'] )
|
||||
) {
|
||||
// Make the src relative the specific plugin or theme.
|
||||
@@ -1115,7 +1141,7 @@ function load_script_textdomain( $handle, $domain = 'default', $path = '' ) {
|
||||
$relative = array_slice( $relative, 2 ); // Remove plugins/<plugin name> or themes/<theme name>.
|
||||
$relative = implode( '/', $relative );
|
||||
} elseif (
|
||||
( ! isset( $plugins_url['path'] ) || strpos( $src_url['path'], $plugins_url['path'] ) === 0 ) &&
|
||||
( ! isset( $plugins_url['path'] ) || str_starts_with( $src_url['path'], $plugins_url['path'] ) ) &&
|
||||
( ! isset( $src_url['host'] ) || ! isset( $plugins_url['host'] ) || $src_url['host'] === $plugins_url['host'] )
|
||||
) {
|
||||
// Make the src relative the specific plugin.
|
||||
@@ -1134,7 +1160,7 @@ function load_script_textdomain( $handle, $domain = 'default', $path = '' ) {
|
||||
} elseif ( ! isset( $src_url['host'] ) || ! isset( $site_url['host'] ) || $src_url['host'] === $site_url['host'] ) {
|
||||
if ( ! isset( $site_url['path'] ) ) {
|
||||
$relative = trim( $src_url['path'], '/' );
|
||||
} elseif ( ( strpos( $src_url['path'], trailingslashit( $site_url['path'] ) ) === 0 ) ) {
|
||||
} elseif ( str_starts_with( $src_url['path'], trailingslashit( $site_url['path'] ) ) ) {
|
||||
// Make the src relative to the WP root.
|
||||
$relative = substr( $src_url['path'], strlen( $site_url['path'] ) );
|
||||
$relative = trim( $relative, '/' );
|
||||
@@ -1157,7 +1183,7 @@ function load_script_textdomain( $handle, $domain = 'default', $path = '' ) {
|
||||
}
|
||||
|
||||
// Translations are always based on the unminified filename.
|
||||
if ( substr( $relative, -7 ) === '.min.js' ) {
|
||||
if ( str_ends_with( $relative, '.min.js' ) ) {
|
||||
$relative = substr( $relative, 0, -7 ) . '.js';
|
||||
}
|
||||
|
||||
@@ -1311,6 +1337,8 @@ function get_translations_for_domain( $domain ) {
|
||||
$noop_translations = new NOOP_Translations();
|
||||
}
|
||||
|
||||
$l10n[ $domain ] = &$noop_translations;
|
||||
|
||||
return $noop_translations;
|
||||
}
|
||||
|
||||
@@ -1326,7 +1354,7 @@ function get_translations_for_domain( $domain ) {
|
||||
*/
|
||||
function is_textdomain_loaded( $domain ) {
|
||||
global $l10n;
|
||||
return isset( $l10n[ $domain ] );
|
||||
return isset( $l10n[ $domain ] ) && ! $l10n[ $domain ] instanceof NOOP_Translations;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1373,8 +1401,8 @@ function get_available_languages( $dir = null ) {
|
||||
if ( $lang_files ) {
|
||||
foreach ( $lang_files as $lang_file ) {
|
||||
$lang_file = basename( $lang_file, '.mo' );
|
||||
if ( 0 !== strpos( $lang_file, 'continents-cities' ) && 0 !== strpos( $lang_file, 'ms-' ) &&
|
||||
0 !== strpos( $lang_file, 'admin-' ) ) {
|
||||
if ( ! str_starts_with( $lang_file, 'continents-cities' ) && ! str_starts_with( $lang_file, 'ms-' ) &&
|
||||
! str_starts_with( $lang_file, 'admin-' ) ) {
|
||||
$languages[] = $lang_file;
|
||||
}
|
||||
}
|
||||
@@ -1428,7 +1456,7 @@ function wp_get_installed_translations( $type ) {
|
||||
if ( '.' === $file[0] || is_dir( WP_LANG_DIR . "$dir/$file" ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( substr( $file, -3 ) !== '.po' ) {
|
||||
if ( ! str_ends_with( $file, '.po' ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( ! preg_match( '/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match ) ) {
|
||||
|
||||
Reference in New Issue
Block a user