Skip Navigation

Open

Reported for: WPML Multilingual CMS 4.6.14

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

Leave a Reply

Please stay on topic and be respectful to others. If you need help with issues not related to this post, use our Support Forum to start a chat or submit a ticket.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>