WPML

问题概述

如果您使用的是 Gravity Forms Polls Add-On 插件,您可能会遇到在默认语言以外的语言中查看时,投票结果不显示翻译内容的问题。此问题主要发生在简码参数设置为 mode="results" 时。当模式设置为 mode=”poll” 时,翻译功能正常。

临时解决方法

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

  • 打开 …/wp-content/plugins/gravityformspolls/class-gf-polls.php 文件。
  • 找到第 2140 行。
  • 在以下代码之前:
    $gpoll_output['summary'] .= $field['field_label'] . '</div></div>';
  • 添加以下代码:
    // WPML Workaround for compsupp-7316 - Part I
    if ( class_exists('Sitepress') ) {
    	$wpml_question = $field['field_label'];
    	$textdomain = 'WordPress';
    	$string_name = 'WPML Workaround : '.substr($wpml_question, 0, 20);
    
    	$wpml_default_lang = apply_filters('wpml_default_language', NULL );
    	$wpml_current_lang = apply_filters( 'wpml_current_language', NULL );
    
    	if ($wpml_default_lang == $wpml_current_lang ) {
    		do_action( 'wpml_register_single_string', $textdomain, $string_name, $wpml_question );
    	}	
    	// Apply the translation to the string
    	$wpml_question = apply_filters('wpml_translate_single_string', $wpml_question , $textdomain, $string_name);
    
    	$field['field_label']   = $wpml_question;  // Replace the title
    }
  • 然后,找到第 2184 行。
  • 将:
    $gpoll_output['summary'] .= sprintf( "<div class='gpoll_choice_wrapper'><div class='gfield_description gpoll_choice_label%s'>%s</div>", $selected_class, rgar( $input, 'label' ) );
  • 替换为:
    // WPML Workaround for compsupp-7316 - Part II
    if ( class_exists('Sitepress') ) {
    	$string = rgar( $input, 'label' );
    	$textdomain = 'WordPress';
    	$string_name = 'WPML Workaround : '.substr($string, 0, 20);
    
    	$wpml_default_lang = apply_filters('wpml_default_language', NULL );
    	$wpml_current_lang = apply_filters( 'wpml_current_language', NULL );
    
    	if ($wpml_default_lang == $wpml_current_lang ) {
    		do_action( 'wpml_register_single_string', $textdomain, $string_name, $string );
    	}	
    	// Apply the translation to the string
    	$string = apply_filters('wpml_translate_single_string', $string , $textdomain, $string_name);
    
    	$wpml_poll_label   = $string;  // Replace the title
    }
    $gpoll_output['summary'] .= sprintf( "<div class='gpoll_choice_wrapper'><div class='gfield_description gpoll_choice_label%s'>%s</div>", $selected_class, $wpml_poll_label );

所有已知问题