WPML
Trạng thái
Đã giải quyết
Được báo cáo cho
WPML String Translation 3.2.15
Đã giải quyết trong
3.2.16
Thẻ chủ đề
Bug

Tổng quan về lỗi

Vấn đề này xảy ra khi các bản dịch tùy chỉnh được lưu trữ trong các tệp .mo không được tải chính xác trên WordPress 6.7.x trở lên. Vấn đề này liên quan đến những thay đổi trong cách WordPress xử lý việc tải bản dịch Just-In-Time (JIT), khiến các mục bản dịch bị hủy thiết lập trong biến toàn cục $l10n.

Giải pháp tạm thời

Hãy đảm bảo bạn đã sao lưu toàn bộ trang web của mình trước khi tiếp tục.


  • Mở tệp …/wp-content/plugins/wpml-string-translation/classes/MO/Hooks/LoadTextDomain.php.

  • Tìm dòng 62.

  • Thay thế:
    	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;
    	}

  • Bằng:
    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;
    	}

Tất cả các lỗi đã ghi nhận →