diff --git a/wp-includes/class-wp-textdomain-registry.php b/wp-includes/class-wp-textdomain-registry.php index b66b5b18a6..b2cbd72fa5 100644 --- a/wp-includes/class-wp-textdomain-registry.php +++ b/wp-includes/class-wp-textdomain-registry.php @@ -150,21 +150,21 @@ class WP_Textdomain_Registry { } /** - * Retrieves .mo files from the specified path. + * Retrieves translation files from the specified path. * * Allows early retrieval through the {@see 'pre_get_mo_files_from_path'} filter to optimize * performance, especially in directories with many files. * * @since 6.5.0 * - * @param string $path The directory path to search for .mo files. - * @return array Array of .mo file paths. + * @param string $path The directory path to search for translation files. + * @return array Array of translation file paths. Can contain .mo and .l10n.php files. */ public function get_language_files_from_path( $path ) { $path = rtrim( $path, '/' ) . '/'; /** - * Filters the .mo files retrieved from a specified path before the actual lookup. + * Filters the translation files retrieved from a specified path before the actual lookup. * * Returning a non-null value from the filter will effectively short-circuit * the MO files lookup, returning that value instead. @@ -174,27 +174,33 @@ class WP_Textdomain_Registry { * * @since 6.5.0 * - * @param null|array $mo_files List of .mo files. Default null. - * @param string $path The path from which .mo files are being fetched. + * @param null|array $files List of translation files. Default null. + * @param string $path The path from which translation files are being fetched. **/ - $mo_files = apply_filters( 'pre_get_language_files_from_path', null, $path ); + $files = apply_filters( 'pre_get_language_files_from_path', null, $path ); - if ( null !== $mo_files ) { - return $mo_files; + if ( null !== $files ) { + return $files; } $cache_key = 'cached_mo_files_' . md5( $path ); - $mo_files = wp_cache_get( $cache_key, 'translations' ); + $files = wp_cache_get( $cache_key, 'translations' ); - if ( false === $mo_files ) { - $mo_files = glob( $path . '*.mo' ); - if ( false === $mo_files ) { - $mo_files = array(); + if ( false === $files ) { + $files = glob( $path . '*.mo' ); + if ( false === $files ) { + $files = array(); } - wp_cache_set( $cache_key, $mo_files, 'translations' ); + + $php_files = glob( $path . '*.l10n.php' ); + if ( is_array( $php_files ) ) { + $files = array_merge( $files, $php_files ); + } + + wp_cache_set( $cache_key, $files, 'translations' ); } - return $mo_files; + return $files; } /** @@ -295,17 +301,18 @@ class WP_Textdomain_Registry { foreach ( $locations as $location ) { $files = $this->get_language_files_from_path( $location ); - $path = "$location/$domain-$locale.mo"; + $mo_path = "$location/$domain-$locale.mo"; + $php_path = "$location/$domain-$locale.l10n.php"; - foreach ( $files as $mo_path ) { + foreach ( $files as $file_path ) { if ( ! in_array( $domain, $this->domains_with_translations, true ) && - str_starts_with( str_replace( "$location/", '', $mo_path ), "$domain-" ) + str_starts_with( str_replace( "$location/", '', $file_path ), "$domain-" ) ) { $this->domains_with_translations[] = $domain; } - if ( $mo_path === $path ) { + if ( $file_path === $mo_path || $file_path === $php_path ) { $found_location = rtrim( $location, '/' ) . '/'; } } diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index 228c40757c..8191b88cee 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -789,10 +789,6 @@ function load_textdomain( $domain, $mofile, $locale = null ) { */ $mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain ); - if ( ! is_readable( $mofile ) ) { - return false; - } - if ( ! $locale ) { $locale = determine_locale(); } @@ -817,14 +813,14 @@ function load_textdomain( $domain, $mofile, $locale = null ) { $preferred_format = 'php'; } - $translation_files = array( $mofile ); + $translation_files = array(); + if ( 'mo' !== $preferred_format ) { - array_unshift( - $translation_files, - substr_replace( $mofile, ".l10n.$preferred_format", - strlen( '.mo' ) ) - ); + $translation_files[] = substr_replace( $mofile, ".l10n.$preferred_format", - strlen( '.mo' ) ); } + $translation_files[] = $mofile; + foreach ( $translation_files as $file ) { /** * Filters the file path for loading translations for the given text domain. @@ -857,7 +853,7 @@ function load_textdomain( $domain, $mofile, $locale = null ) { } } - return true; + return false; } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 7436f1d88e..524d2f9deb 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.5-alpha-57515'; +$wp_version = '6.5-alpha-57516'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.