- Statut
- En attente de l’auteur
- Extension/thème associé
- WP Grid Builder
- Étiquettes de sujet
- Compatibility
Aperçu de l’anomalie
Lors de l’utilisation de Grid Builder avec WPML et Advanced Custom Fields (ACF), il y a un problème avec les Facets utilisant des champs personnalisés. Même si les libellés des champs ACF sont traduits dans le back-end, ils ne se reflètent pas sur le front-end.
Solution de contournement
Veuillez vous assurer d’avoir une sauvegarde complète de votre site avant de continuer.
Pour les champs de sélection
- Ouvrez le fichier functions.php de votre thème.
- Ajoutez le code suivant :
// 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 ); - Visitez la page contenant les facettes dans la langue d’origine pour enregistrer les chaînes.
- Allez sur la page WPML > Traduction de chaînes et traduisez les chaînes.
Remarque : Selon la façon dont vos facettes ont été créées, cet autre extrait de code peut être 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 );