WPML
Status
Resolvido
Relatado para
WPML String Translation 3.2.15
Resolvido em
3.2.16
Tags de tópico
Bug

Visão geral do problema

Esse problema ocorre quando traduções personalizadas armazenadas em arquivos .mo não carregam corretamente no WordPress 6.7.x ou posterior. O problema está relacionado a mudanças na forma como o WordPress lida com o carregamento de traduções Just-In-Time (JIT), fazendo com que as entradas de tradução sejam removidas da variável global $l10n.

Solução alternativa

Certifique-se de ter um backup completo do seu site antes de prosseguir.


  • Abra o arquivo …/wp-content/plugins/wpml-string-translation/classes/MO/Hooks/LoadTextDomain.php.

  • Procure a linha 62.

  • Substitua:
    	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;
    	}

  • Por:
    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;
    	}

Todos os problemas conhecidos →