Skip Navigation

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;
    	}
    

5 Responses to “WordPress 6.7 - .mo Files Not Loaded And Leading to Missing Translations on Front-End”

    • Although we don’t have an ETA, there is an upcoming release that should help fixing this issue soon.
      We will keep this page updated.

    • Although we don’t have an ETA, there is an upcoming release that should help fixing this issue soon.
      We will keep this page updated.