Make WordPress Core


Ignore:
Timestamp:
11/20/2024 02:48:40 AM (2 years 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].

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

File:
1 edited

Legend:

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

    r58591 r59430  
    154154         */
    155155        public function set_custom_path( $domain, $path ) {
     156                // If just-in-time loading was triggered before, reset the entry so it can be tried again.
     157
     158                if ( isset( $this->all[ $domain ] ) ) {
     159                        $this->all[ $domain ] = array_filter( $this->all[ $domain ] );
     160                }
     161
     162                if ( empty( $this->current[ $domain ] ) ) {
     163                        unset( $this->current[ $domain ] );
     164                }
     165
    156166                $this->custom_paths[ $domain ] = rtrim( $path, '/' );
    157167        }
    … …  
    337347                 * using load_plugin_textdomain/load_theme_textdomain, use that one.
    338348                 */
    339                 if ( 'en_US' !== $locale && isset( $this->custom_paths[ $domain ] ) ) {
     349                if ( isset( $this->custom_paths[ $domain ] ) ) {
    340350                        $fallback_location = rtrim( $this->custom_paths[ $domain ], '/' ) . '/';
    341351                        $this->set( $domain, $locale, $fallback_location );
Note: See TracChangeset for help on using the changeset viewer.