WPML
Status
Resolved
Reported for
WPML String Translation 3.2.15
Resolved in
3.2.16
Topic tags
Bug

Overview of the issue

This issue arises when custom translations stored in .mo files fail to load correctly on WordPress 6.7.x or later. The problem is linked to changes in how WordPress handles Just-In-Time (JIT) translation loading, causing translation entries to be unset in the $l10n global variable.

Workaround

Please, make sure of having a full site backup of your site before proceeding.


  • Open …/wp-content/plugins/wpml-string-translation/classes/MO/Hooks/LoadTextDomain.php file.

  • Look for line 62.

  • Replace:
    	public function overrideLoadTextDomain( $override, $domain, $mofile ) {
    		if ( ! $mofile ) {
    			return $override;
    		}
    
    		if ( ! $this->isCustomMOLoaded( $domain ) ) {
    			remove_filter( 'override_load_textdomain', [ $this, 'overrideLoadTextDomain' ], 10 );
    			$locale      = $this->file_locale->get( $mofile, $domain );
    			$this->loadCustomMOFile( $domain, $mofile, $locale );
    			add_filter( 'override_load_textdomain', [ $this, 'overrideLoadTextDomain' ], 10, 3 );
    		}
    
    		$this->loaded_mo_dictionary->addFile( $domain, $mofile );
    
    		return $override;
    	}

  • With:
    public function overrideLoadTextDomain( $override, $domain, $mofile ) {
    		if ( ! $mofile ) {
    			return $override;
    		}
    
    		if ( ! $this->isCustomMOLoaded( $domain ) ) {
                $locale      = $this->file_locale->get( $mofile, $domain );
                $wpml_mofile = $this->file_manager->get( $domain, $locale );
    
                if ( ! file_exists( $mofile ) && $wpml_mofile ) {
                    add_filter( 'load_translation_file', function($file) use ( $mofile, $wpml_mofile ) {
                        if ( $file === $mofile ) {
                            return $wpml_mofile;
                        }
                        return $file;
                        // unset this own hook, just to be used once.
                    });
                    return $override;
                }
    			remove_filter( 'override_load_textdomain', [ $this, 'overrideLoadTextDomain' ], 10 );
    
    			$this->loadCustomMOFile( $domain, $mofile, $locale );
    			add_filter( 'override_load_textdomain', [ $this, 'overrideLoadTextDomain' ], 10, 3 );
    		}
    
    		$this->loaded_mo_dictionary->addFile( $domain, $mofile );
    
    		return $override;
    	}

All known issues →