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 3 replies, has 2 voices.

Last updated by Alejandro 1 year ago.

Assigned support staff: Alejandro.

Author Posts
October 15, 2018 at 7:52 am #2816450

Apulia Vending s.r.l.

Tell us what you are trying to do?
I want to translate the destination page of the following code which opens a thank you page after a form submission. Can you suggest ho to get it, or give us a better idea?
window.location.href = '/thank-you';

Is there any documentation that you are following?
Is there a similar example that we can see?
What is the link to your site?
hidden link

October 15, 2018 at 9:23 am #2816762


Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

Welcome to WPML Support!
I'll do my best to help you sort this issue out.

It would be very useful if you could provide me with further information, otherwise it will be difficult for me to give you a detailed solution.

In this case, i'd like to specifically know where does this code come from and in what page i can see it.

In the meantime i'll give you a few solutions that might help your case:

1) If it's a plugin/theme that is creating the code, then you will probably find and translate it in WPML > Strings Translation

2) If the code is hardcoded in the theme/plugin, since it seems to be a JavaScript function, then you need to use the WordPress Built-in Function which documentation you can find here:

3) You can also take a look at how to translate theme options:
This will help you in case the above mentioned code comes from an option in your theme. Options are a bit particular, and this guide will surely be of help if that's the case.
Afterwards, you will find that code in WPML > String Translation.

It would be very helpful for us if you point out which solution helped your case (that's if they helped you, of course)

If none of the solutions above worked, then please kindly provide me with more information and i'll do my best to help you solve this problem.

October 22, 2018 at 10:40 am #2837677

Apulia Vending s.r.l.

sorry for the delay.

In PHP file I wrote the code you find below that creates the contact form at the top right of the page.

if (get_locale() == 'en_GB') { 
    $relang = 'en';
else if (get_locale() == 'it_IT') {
    $relang = 'it';
else if (get_locale() == 'pt_PT') {
    $relang = 'pt';
<script src=\'<em><u>hidden link</u></em>'.$relang.'\'></script>
<div class="g-recaptcha" data-sitekey="6LensiwUAAAAALtanbI2nxFqxVrkuaApwpesyvBi" data-callback="enableBtn" id="button1"></div><br>
<center><input type="checkbox" id="terms" onclick="checkTerms()"> I accept <a href="">term of use</a></center>
<input type="hidden" name="tour-id" value="' . get_the_ID() . '" />
<input type="submit" id="sendmsg" class="tourmaster-button" value="' . esc_html__('Submit Enquiry', 'tourmaster') . '" disabled/>
  var chaptched = false;
  function enableBtn(){ 
    chaptched = true;
        document.getElementById("sendmsg").disabled = false;
  function checkTerms(){
    if(document.getElementById("terms").checked && chaptched)
        document.getElementById("sendmsg").disabled = false;

I would like to translate "terms of use" page url with WPML.

In JS file I managed a redirect link of a ajax secces code, as below, to this page that I would manage with WPML:

    type: 'POST',
    url: form.attr('data-ajax-url'),
    data: { action: form.attr('data-action'), data: tourmaster_get_booking_detail(form) },
    dataType: 'json',
    error: function( jqXHR, textStatus, errorThrown ){
      // print error message for debug purpose
      console.log(jqXHR, textStatus, errorThrown);
    success: function( data ){
      if( typeof(data.message) != 'undefined' ){
        if( data.status == 'success' ){
          form.find('input[name], textarea[name], select[name]').val('');
        window.location.href = '/thank-you';  <--- THIS LINE REDIRECT USER TO THANK-YOU PAGE

My code is hardcoded in the theme/plugin and I need to use the WordPress Built-in Function but I need some help for this purpose.

Best regards

October 22, 2018 at 1:56 pm #2838323


Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)


In order to translate a string you are correct by saying that you need to use the built-in WP function.

In your case, since the localization is being made in JavaScript, you should use the wp_localize_script() function. You can find its documentation here:

Another way to do so is by following my colleague's advice on this ticket: . You could copy this code and add it in the current place of the destination link ("/thank-you/"):

window.location.href = "<?php _e( '/thank-you/', 'terrachevive' ); ?>";

you can later translate that newly registered string in any language you want by using WPML's String Translations (WPML > String Translation).

If the localized string doesn't appear in WPML's String Translation, after making sure you localized the script correctly, Please re-scan your theme. You can do so by going to WPML > Theme and Plugins Localization. Find your theme, select it and click "Scan selected themes for strings" under the "Strings in the themes" section.

After you scan it you should now find it in WPML > String Translation, under the name of the text domain you gave it (in this example it would be under "terrachevive" ).

Let me know how it goes.