WPML
状态
等待作者
相关插件/主题
WP Grid Builder
主题标签
Compatibility

问题概述

当将Grid BuilderWPMLAdvanced Custom Fields (ACF)结合使用时,使用自定义字段的Facets会出现问题。尽管 ACF 字段标签已在后台翻译,但并未反映在前端。

临时解决方法

在继续操作之前,请确保对您的站点进行完整备份

对于 Select 字段


  • 打开主题的 functions.php 文件。

  • 添加以下代码:
    // 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 );
  • 在原始语言下访问包含分面的页面以注册字符串。
  • 转到 WPML > 字符串翻译页面并翻译字符串。

注意:根据分面的构建方式,以下代码片段可能会有所帮助:

// 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 );

所有已知问题 →