Make WordPress Core


Ignore:
Timestamp:
11/20/2024 01:32:57 PM (3 months ago)
Author:
desrosj
Message:

i18n: Account for load_*_textdomain() after JIT loading.

When load_*_textdomain() functions are called after WordPress has already attempted just-in-time loading of translations, nothing happens.

This updates the related logic to retry translation loading when a custom path is set to ensure all translations are available.

Additionally, this also fixes cases where an en_US.mo file is provided with non-English strings to override the default language.

Follow up to [59157].

Reviewed by SergeyBiryukov.
Merges [59430] to the 6.7 branch.

Props swissspidy, peterwilsoncc, desrosj, apermo, sergeybiryukov, wildworks, tigriweb, twvania, looswebstudio, stimul, audrasjb, finntown, bluantinoo, timwhitlock, albigdd.
See #62337.

Location:
branches/6.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.7

  • branches/6.7/src/wp-includes/l10n.php

    r59264 r59433  
    986986 * @since 6.7.0 Translations are no longer immediately loaded, but handed off to the just-in-time loading mechanism.
    987987 *
     988 * @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry.
     989 * @global array<string, WP_Translations|NOOP_Translations> $l10n An array of all currently loaded text domains.
     990 *
    988991 * @param string       $domain          Unique identifier for retrieving translated strings
    989992 * @param string|false $deprecated      Optional. Deprecated. Use the $plugin_rel_path parameter instead.
     
    995998function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) {
    996999    /** @var WP_Textdomain_Registry $wp_textdomain_registry */
    997     global $wp_textdomain_registry;
     1000    /** @var array<string, WP_Translations|NOOP_Translations> $l10n */
     1001    global $wp_textdomain_registry, $l10n;
    9981002
    9991003    if ( ! is_string( $domain ) ) {
     
    10121016    $wp_textdomain_registry->set_custom_path( $domain, $path );
    10131017
     1018    // If just-in-time loading was triggered before, reset the entry so it can be tried again.
     1019    if ( isset( $l10n[ $domain ] ) && $l10n[ $domain ] instanceof NOOP_Translations ) {
     1020        unset( $l10n[ $domain ] );
     1021    }
     1022
    10141023    return true;
    10151024}
     
    10231032 *
    10241033 * @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry.
     1034 * @global array<string, WP_Translations|NOOP_Translations> $l10n An array of all currently loaded text domains.
    10251035 *
    10261036 * @param string $domain             Text domain. Unique identifier for retrieving translated strings.
     
    10311041function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) {
    10321042    /** @var WP_Textdomain_Registry $wp_textdomain_registry */
    1033     global $wp_textdomain_registry;
     1043    /** @var array<string, WP_Translations|NOOP_Translations> $l10n */
     1044    global $wp_textdomain_registry, $l10n;
    10341045
    10351046    if ( ! is_string( $domain ) ) {
     
    10401051
    10411052    $wp_textdomain_registry->set_custom_path( $domain, $path );
     1053
     1054    // If just-in-time loading was triggered before, reset the entry so it can be tried again.
     1055    if ( isset( $l10n[ $domain ] ) && $l10n[ $domain ] instanceof NOOP_Translations ) {
     1056        unset( $l10n[ $domain ] );
     1057    }
    10421058
    10431059    return true;
     
    10571073 *
    10581074 * @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry.
     1075 * @global array<string, WP_Translations|NOOP_Translations> $l10n An array of all currently loaded text domains.
    10591076 *
    10601077 * @param string       $domain Text domain. Unique identifier for retrieving translated strings.
     
    10651082function load_theme_textdomain( $domain, $path = false ) {
    10661083    /** @var WP_Textdomain_Registry $wp_textdomain_registry */
    1067     global $wp_textdomain_registry;
     1084    /** @var array<string, WP_Translations|NOOP_Translations> $l10n */
     1085    global $wp_textdomain_registry, $l10n;
    10681086
    10691087    if ( ! is_string( $domain ) ) {
     
    10761094
    10771095    $wp_textdomain_registry->set_custom_path( $domain, $path );
     1096
     1097    // If just-in-time loading was triggered before, reset the entry so it can be tried again.
     1098    if ( isset( $l10n[ $domain ] ) && $l10n[ $domain ] instanceof NOOP_Translations ) {
     1099        unset( $l10n[ $domain ] );
     1100    }
    10781101
    10791102    return true;
Note: See TracChangeset for help on using the changeset viewer.