Skip navigation

Waiting for author

Topic Tags: Compatibility

Overview of the issue

When using Grid Builder with WPML and Advanced Custom Fields (ACF), there’s a problem with Facets using custom fields. Even though the ACF field labels are translated in the backend, they are not reflected in the frontend.

Workaround

Please, make sure of having a full backup of your site before proceeding.

For Select fields

  • Open your theme’s functions.php file.
  • Add the following code:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    // 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 );
  • Visit the page with the facets in the original language to register the strings.
  • Go to WPML > String Translation page and translate the strings.

Note: Depending on how your Facets were built, this other snippet may be helpful:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// 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 );

комментария 2 на “Grid Builder - Facets using ACF fields labels are not translated in frontend”

  1. I haven’t had any luck with this. Is anything in the code specific to the website? Do I need to make any changes?

    I was able to get Facets to register in the string translation, and I’ve translated them, but the facets still aren’t appearing on the front end.

Написать ответ

Пожалуйста, оставайтесь в теме и будьте уважительны к другим. Если Вам нужна помощь по вопросам, не относящимся к этому сообщению, воспользуйтесь нашим Форумом поддержки, чтобы начать чат или отправить тикет.

Вы можете использовать эти метки:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>