Make WordPress Core

Changeset 57639

Timestamp:
02/16/2024 10:26:14 AM (5 months ago)
Author:
swissspidy
Message:

I18N: Prevent incorrect language dropdown entries when there are .l10n.php files.

In [57516], the just-in-time translation loading logic was enhanced to support cases where only .l10n.php translation exist but no .mo or .po files. This caused a slight regression in get_available_languages(), which uses the list of files to populate the language dropdown list on the settings page.

To address this, the new file extension is now properly stripped off, and the resulting file list is de-duplicated. New test files are added to allow the existing tests to cover this new scenario.

See #59656.
Fixes #60553.

Location:
trunk
Files:
9 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-textdomain-registry.php

    r57516 r57639  
    315315                if ( $file_path === $mo_path || $file_path === $php_path ) {
    316316                    $found_location = rtrim( $location, '/' ) . '/';
     317
    317318                }
    318319            }
  • trunk/src/wp-includes/l10n.php

    r57516 r57639  
    14361436
    14371437/**
    1438  * Gets all available languages based on the presence of *.mo files in a given directory.
     1438 * Gets all available languages based on the presence of *.mo files in a given directory.
    14391439 *
    14401440 * The default directory is WP_LANG_DIR.
     
    14421442 * @since 3.0.0
    14431443 * @since 4.7.0 The results are now filterable with the {@see 'get_available_languages'} filter.
     1444
    14441445 *
    14451446 * @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry.
     
    14481449 *                    Default WP_LANG_DIR.
    14491450 * @return string[] An array of language codes or an empty array if no languages are present.
    1450  *                  Language codes are formed by stripping the .mo extension from the language file names.
     1451 *                  Language codes are formed by stripping the extension from the language file names.
    14511452 */
    14521453function get_available_languages( $dir = null ) {
     
    14611462        foreach ( $lang_files as $lang_file ) {
    14621463            $lang_file = basename( $lang_file, '.mo' );
     1464
     1465
    14631466            if ( ! str_starts_with( $lang_file, 'continents-cities' ) && ! str_starts_with( $lang_file, 'ms-' ) &&
    14641467                ! str_starts_with( $lang_file, 'admin-' ) ) {
     
    14761479     * @param string   $dir       The directory where the language files were found.
    14771480     */
    1478     return apply_filters( 'get_available_languages', $languages, $dir );
     1481    return apply_filters( 'get_available_languages', , $dir );
    14791482}
    14801483
Note: See TracChangeset for help on using the changeset viewer.