- Trạng thái
- Đang chờ nhà phát triển
- Plugin/giao diện liên quan
- WP Grid Builder
- Thẻ chủ đề
- Compatibility
Tổng quan về lỗi
Khi sử dụng Grid Builder với WPML và Advanced Custom Fields (ACF), có một vấn đề xảy ra với Facets sử dụng các trường tùy chỉnh. Mặc dù các nhãn trường ACF được dịch trong backend, chúng không được phản ánh trên frontend.
Giải pháp tạm thời
Vui lòng đảm bảo tạo bản sao lưu toàn bộ trang web của bạn trước khi tiếp tục.
Đối với các trường Select
- Mở tệp functions.php trong giao diện của bạn.
- Thêm mã sau:
// 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 ); - Truy cập trang có các facet bằng ngôn ngữ gốc để đăng ký các chuỗi.
- Đi tới trang WPML > Dịch chuỗi và dịch các chuỗi.
Lưu ý: Tùy thuộc vào cách các Facet của bạn được xây dựng, đoạn mã khác này có thể hữu ích:
// 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 );