Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 25 replies, has 3 voices.

Last updated by Kristof 3 years, 9 months ago.

Assigned support staff: Shekhar Bhandari.

Author Posts
October 24, 2017 at 12:12 pm #1409982

Kristof

We need to translate a survey we created with the WordPress Simple Survey plugin. However, the questions, answers and other strings do not appear in the String Translation table.

They are stored in the database in the tables "wptr_wpss_questions_30", "wptr_wpss_answers_30", "wptr_wpss_category_30", "wptr_wpss_quizzes_30" and "wptr_wpss_routes_30".

How can we still translate those?

October 25, 2017 at 12:32 pm #1411287

Bigul
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi Kristof,

Welcome to the WPML support forum. I will do my best to help you to resolve these issues.

To translate the custom contents, you have to do custom coding by using WPML hooks. You can use *wpml_register_single_string* and *wpml_translate_single_string* hooks to register and translate the custom contents.

Please check the following documentation for more details and let me know your feedback.

https://wpml.org/wpml-hook/wpml_register_single_string/

https://wpml.org/wpml-hook/wpml_translate_single_string/

https://wpml.org/documentation/support/string-package-translation/

sample code

//The string for translation
$string = "The sample string";
 
//register the string for translation
do_action( 'wpml_register_single_string', 'my-string context', 'my-string', $string );
 
//display original string or translated string
echo apply_filters( 'wpml_translate_single_string', $string, 'my-string context', 'my-string' );

--
Thanks!

Bigul

October 26, 2017 at 10:00 am #1412687

Kristof

Hi, I have found the code that queries and displays the questions and answers, but I have no idea how to apply your provided code onto this.

function wpss_get_questions($questions){

  $o = '';

  foreach($questions->questions as $i => $q){
    
    $o .= '<div id="wpss_question_panel_'.$q['question']->id.'" class="wpss_panel_'.($i+1).' wpss-form-panel wpss-hidden">' . "\n"; 
    $o .=   '<fieldset>'."\n";

    $o .=     '<div id="wpss_question_'.$q['question']->id.'" class="wpss-question">' . "\n";
    $o .=       wpss_wysiwyg_output( $q['question']->question );
    $o .=      '<div class="wpss-clear"></div>';
    $o .=     '</div>'."\n";

    $o .=     '<div class="answers">'."\n";
    $o .=        wpss_get_answers( $q['answers'], $q['question']->type, $q['question']->id );
    $o .=     '</div>'."\n";

    $o .=   '</fieldset>'."\n";
    $o .= '</div>'."\n";

  }

  return $o;
}
October 26, 2017 at 4:51 pm #1413304

Bigul
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi Kristof,

Thank you for the updates. Are you using the free version of the *WordPress Simple Survey* plugin, https://wordpress.org/plugins/wordpress-simple-survey/?

Please try with the following modified code after a site backup and let me know your feedback.

function wpss_get_questions($questions){
 
  $o = '';
 
  foreach($questions->questions as $i => $q){
     
    $o .= '<div id="wpss_question_panel_'.$q['question']->id.'" class="wpss_panel_'.($i+1).' wpss-form-panel wpss-hidden">' . "\n"; 
    $o .=   '<fieldset>'."\n";
 
    $o .=     '<div id="wpss_question_'.$q['question']->id.'" class="wpss-question">' . "\n";
	
	//The string for translation
	$wpss_question = wpss_wysiwyg_output( $q['question']->question );  
	//register the string for translation
	do_action( 'wpml_register_single_string', 'Simple Survey', 'Questions '.$q['question']->id, $wpss_question );  
	//display original string or translated string	
    $o .=  apply_filters( 'wpml_translate_single_string', $wpss_question, 'Simple Survey', 'Questions '.$q['question']->id );  
   
    $o .=      '<div class="wpss-clear"></div>';
    $o .=     '</div>'."\n";
 
    $o .=     '<div class="answers">'."\n";

	//The string for translation
	$wpss_answers = wpss_get_answers( $q['answers'], $q['question']->type, $q['question']->id );  
	//register the string for translation
	do_action( 'wpml_register_single_string', 'Simple Survey', 'Answers '.$q['question']->id, $wpss_answers );  
	//display original string or translated string	    
    $o .=  apply_filters( 'wpml_translate_single_string', $wpss_answers, 'Simple Survey', 'Answers '.$q['question']->id );  
		
    $o .=     '</div>'."\n";
 
    $o .=   '</fieldset>'."\n";
    $o .= '</div>'."\n";
 
  }
 
  return $o;
}

After adding this modification, visit the frontend. It will help you to register the Strings for translation. Visit WPML>>String Translation and translate the string to the secondary language. Then make sure you are getting the expected result or not.

To help you faster, I've enabled debug information for this support ticket. Please see this link for how to get this information from your site and give it to us: http://wpml.org/faq/provide-debug-information-faster-support/

--
Thanks!

Bigul

October 27, 2017 at 9:06 am #1413831

Kristof

Hi,
Yes we are using the free version of the plugin.

Your code indeed helped to register these strings as you can see on hidden link

The questions are registered perfectly like

<p>Veranderingen worden met veel respect voor de medewerkers ingevoerd, en er wordt goed over gecommuniceerd. </p>

although in the DB, they are stored without the <p> tag,

but the answers are a bit more cryptic

<div class="answer_text"> <input type="radio" class="wpss-radio" name="wpss[questions][6][]" id="answer_25" value="25" /> <label for="answer_25">Meestal</label> <div class="wpss-clear"></div></div> <div class="answer_text"> <input type="radio" class="wpss-radio" name="wpss[questions][6][]" id="answer_26" value="26" /> <label for="answer_26">Vrij vaak</label> <div class="wpss-clear"></div></div> <div class="answer_text"> <input type="radio" class="wpss-radio" name="wpss[questions][6][]" id="answer_27" value="27" /> <label for="answer_27">Zelden</label> <div class="wpss-clear"></div></div> <div class="answer_text"> <input type="radio" class="wpss-radio" name="wpss[questions][6][]" id="answer_28" value="28" /> <label for="answer_28">Bijna nooit</label> <div class="wpss-clear"></div></div>

I know enough html to edit this block, but I am a bit concerned about the IDs and also because in the wptr_wpss_answers_30 table, they are stored as on the screenshot.

Screenshot_4.png
October 27, 2017 at 11:32 am #1413984

Kristof

I also need some help with this array, when I change

	$o .= '<h2>'. $cat->category->name  .'</h2>';

into

	//The string for translation
	$wpss_category_name = $cat->category->name;
  	//register the string for translation
	do_action( 'wpml_register_single_string', 'Simple Survey', 'Category Name', $wpss_category_name );
  	//display original string or translated string
	$o .= '<h2>'.apply_filters( 'wpml_translate_single_string', $wpss_category_name, 'Simple Survey', 'Category Name' ).'</h2>';

all my categories have the same name.
Same for

	//The string for translation
	$wpss_category_recommandation = $cat->category->recommandation;
  	//register the string for translation
	do_action( 'wpml_register_single_string', 'Simple Survey', 'Category Recommandation', $wpss_category_recommandation);
  	//display original string or translated string
	$o .= apply_filters( 'wpml_translate_single_string', $wpss_category_recommandation, 'Simple Survey', 'Category Recommandation' );
October 27, 2017 at 3:04 pm #1414239

Bigul
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi Kristof,

Thank you for the updates. Sorry, we have some limitations to make this plugin 100% compatible. Becuase they are not using the WordPress default tables and the plugin is not updated for last three years. But we will try our best to help you.

Now we are just registering the Question and Answers output as strings. So it will not change the code structure of the Plugin. Otherwise, we have to do a lot of custom work to achieve it and it is out of the scope of our support. Please translate the Answer label only. For an example Vrij vaak to Vrij vaak FR. Please check the following for more details. Hope it will help you to keep the answer IDs in *wptr_wpss_answers_30* table without any changes.

<div class="answer_text"> <input type="radio" class="wpss-radio" name="wpss[questions][6][]" id="answer_25" value="25" /> <label for="answer_25">Meestal FR</label> <div class="wpss-clear"></div></div> <div class="answer_text"> <input type="radio" class="wpss-radio" name="wpss[questions][6][]" id="answer_26" value="26" /> <label for="answer_26">Vrij vaak FR</label> <div class="wpss-clear"></div></div> <div class="answer_text"> <input type="radio" class="wpss-radio" name="wpss[questions][6][]" id="answer_27" value="27" /> <label for="answer_27">Zelden FR</label> <div class="wpss-clear"></div></div> <div class="answer_text"> <input type="radio" class="wpss-radio" name="wpss[questions][6][]" id="answer_28" value="28" /> <label for="answer_28">Bijna nooit FR</label> <div class="wpss-clear"></div></div>

Please let me know more details about the following for a better understanding. So I can try it on my local server.

$o .= '<h2>'. $cat->category->name  .'</h2>';
$o .= $cat->category->recommandation;

1) Have you visited the Page in frontend after modifying the code?

2) Please let me know the steps to view this result in frontend?

3) Which file or function of *WordPress Simple Survey* you have modified for this purpose

--
Thanks!

Bigul

October 30, 2017 at 8:52 am #1415354

Kristof

I know, we are a bit stuck with this plugin because of our modifications, but we did not find any plugin that had this particular feature. We have given a weight to each answer, so that after all questions we can give recommandations based on the answers.

A recommandation consists of a "Category Name" and a "Recommandation". But when we apply the register string on either, we get the same title for each recommandation or the same recommandation for each category. There is an issue with the foreach loop. The variable is set and does not change on the next foreach loop.

1) yes, this is how we discovered that there was a problem
2) fill out the entire survey, then enter a Name and Email and click Next, on the next page, you get the Recommandations
3) \views\quiz\view.quiz.php

October 30, 2017 at 4:44 pm #1415983

Bigul
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi Kristof,

Thank you for the updates. I would like to access admin area of your site for further checking. Please fill the private details fields after a full site backup. Check the following links for more details about our private information sharing.

hidden link

https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

Please allow me to make a duplicator copy of your site using Duplicator plugin(https://wordpress.org/plugins/duplicator/) for debugging the issue on my local server.

--
Thanks!

Bigul

November 6, 2017 at 6:34 pm #1422431

Bigul
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi Kristof,

Thank you for the login information. I made a duplicator copy of your site now. Will debug it on my local server and get back to you. Please wait.

--
Thanks!

Bigul

November 7, 2017 at 9:38 am #1422844

Bigul
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi Kristof,

It is working for me when I tried with the following code. Please try with it after a backup and let me know your feedback.

   $o .= '<div class="wpss-result">';
	
	$wpss_category_name = $cat->category->name;
	do_action( 'wpml_register_single_string', 'Simple Survey', 'Category Name '.$cat->category->id, $wpss_category_name );
	$wpss_category_name = apply_filters( 'wpml_translate_single_string', $wpss_category_name, 'Simple Survey', 'Category Name '.$cat->category->id );
	
    $o .= '<h2>'. $wpss_category_name  .'</h2>';
	
	$wpss_category_recommandation = $cat->category->recommandation;
	do_action( 'wpml_register_single_string', 'Simple Survey', 'Category Recommandation '.$cat->category->id, $wpss_category_recommandation );
	$wpss_category_recommandation = apply_filters( 'wpml_translate_single_string', $wpss_category_recommandation, 'Simple Survey', 'Category Recommandation '.$cat->category->id );
	
    $o .=  $wpss_category_recommandation;
    $o .= '</div>';

Please check the attached images for more details.

--
Thanks!

Bigul

2017-11-07_1509.png
2017-11-07_1507.png
November 10, 2017 at 3:52 pm #1427214

Kristof

This has registered both the Category and the Recommandation perfectly, however, as there are only 3 Recommandations shown after each survey, only those 3 have been registeren. Any idea how I can show them all in the WPML String Translation? I have no idea which answers I need to give in the survey, in order to display 3 different Recommandations.

November 13, 2017 at 10:47 am #1428723

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hi there,

Bigul is on vacations, so I am taking care of this ticket, hope that is OK. 🙂

I am currently working on this ticket and will respond to you soon.

Thanks

November 14, 2017 at 3:53 am #1429630

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hi there,

I have gone through the whole ticket and I can see that you are having issues using our custom hooks and filters properly.

I tried to download the duplicator package to help you further but it seems your login path has been changed, so could you please review the login path again and provide me the correct details.

Look forward to your reply.

Thanks

November 16, 2017 at 12:29 pm #1432630

Kristof

The login path is correct and Bigul was already able to create a local copy of the site, so the Package also works.