WPML
Stato
In attesa dell’autore
Plugin/tema correlato
WP Grid Builder
Tag dell’argomento
Compatibility

Panoramica del problema

Quando usi Grid Builder con WPML e Advanced Custom Fields (ACF), si verifica un problema con i Facets che utilizzano i campi personalizzati. Anche se le etichette dei campi ACF sono tradotte nel back-end, non si riflettono nel front-end.

Soluzione alternativa

Assicurati di avere un backup completo del tuo sito prima di procedere.

Per i campi Select


  • Apri il file functions.php del tuo tema.

  • Aggiungi il seguente codice:
    // WPML Workaround for wpmlsupp-11647
    function wpml_wpmlsupp11647_translate_facet_choices( $choices, $facet ) {
    
    	if ( class_exists('Sitepress') ) {
    		foreach ($choices as &$choice) {
    			$string = $choice->facet_name;
    			$textdomain = 'facets';
    			$string_name = 'Facet: '.substr($string, 0, 20);
    		
    			if ( apply_filters('wpml_default_language', NULL ) == apply_filters( 'wpml_current_language', NULL )) {
    				do_action( 'wpml_register_single_string', $textdomain, $string_name, $string );
    			}	
    			// Apply the translation to the string
    			$choice->facet_name = apply_filters('wpml_translate_single_string', $string , $textdomain, $string_name);
    		}
    	}
    
    	return $choices;
    
    }
    
    add_filter( 'wp_grid_builder/facet/choices', 'wpml_wpmlsupp11647_translate_facet_choices', 10, 2 );
  • Visita la pagina con le facet nella lingua originale per registrare le stringhe.
  • Vai alla pagina WPML > Traduzione stringhe e traduci le stringhe.

Nota: a seconda di come sono state create le tue facet, quest’altro snippet potrebbe essere utile:

// WPML Workaround for compsupp-7453
function wpml_compsupp7453_translate_facet_block_custom_field( $output ) {
 
    if ( class_exists('Sitepress') ) {
        if( is_string($output) ) {

            $string = $output;
            $textdomain = 'facets';
            $string_name = 'Facet: '.substr($string, 0, 20);
         
            if ( apply_filters('wpml_default_language', NULL ) == apply_filters( 'wpml_current_language', NULL )) {
                do_action( 'wpml_register_single_string', $textdomain, $string_name, $string );
            }   
            // Apply the translation to the string
            $output = apply_filters('wpml_translate_single_string', $string , $textdomain, $string_name);
        }
    }
 
    return $output ;
 
}
 
add_filter( 'wp_grid_builder/block/custom_field', 'wpml_compsupp7453_translate_facet_block_custom_field', 99, 2 );

Tutti i problemi noti →