1

I want to translate a Webform. I know it's very easy to achieve if there are separate Webform nodes for each language but I don't want to do that, I want to keep a single node.

I have already tried the Webform Localization module:

As per the readme of this module, it says to keep a single node enable
"localization by string translation" fieldset in the form settings

Which I have done.

I have also refreshed the i18n_string, as suggested in module readme.

Issue here is, even with above settings when I click on translate tab of the Webform node, it creates new node.

So are there any other settings I'm missing or this module is not working as its currently in under development.

1

3 Answers 3

4

The method in the documentation is working:

  1. Go to the Webform Form settings at node/1/webform/configure
  2. Check "localization by string translation" and "Expose webform component strings suitable for translation."
  3. If dealing with an existing webform, then go to Go to Configuration -> Translate interface -> Strings
  4. Enable "Webform localization" checkbox (this is important)
  5. And Refresh Strings Then you will be able to see the string in Configuration -> Translate interface -> Translate

At least this works for me.

-1

If you have "localization by string translation" then it will create additional nodes each with their own title, path etc, but they will share a single webform. Use the translate tab just to change the node title etc, but to translate elements in the webform, go to /admin/config/regional/translate/translate and search of each field label etc in turn.

1
  • Yes, I have tried that as well, but the main issue here is that there is "Language switcher" block on header and that block does not allow to change the language until there is a translated node for that node. And anyhow I want to keep a single node. By the I have managed that by form alter and some custom menu stuff. Working exactly in a way I wanted.
    – Parth Vora
    Commented Aug 17, 2015 at 11:13
-1

Might not be an efficient way, but I don't get any other way to do that.

Here is a solution to keep a single Webform node with multilingual functionality:

Adding translated strings for each Webform element label not worked.

So I done something like that in form alter hook:

if(strpos($form_id, 'webform_client_form') !== false) {
    $form['#submit'][] = 'gt_custom_contact_webform_submit';
    $form['submitted']['your_name']['#title'] = t($form['submitted']['your_name']['#title']);
    $form['submitted']['your_e_mail_address']['#title'] = t($form['submitted']['your_e_mail_address']['#title']);
    $form['submitted']['subject']['#title'] = t($form['submitted']['subject']['#title']);
    $form['submitted']['message']['#title'] = t($form['submitted']['message']['#title']); 
    $form['actions']['submit']['#value'] = t($form['actions']['submit']['#value']); 
  }

Add translated strings for each Webform element label from here:

/admin/config/regional/translate/translate

Now if you are using language switcher block, you will see it will not allow to change the language.

To solve that:

function gt_custom_menu() {
  $items['contact-us'] = array(
    'title callback' => 'gt_custom_contact_form_title',
    'page callback' => 'gt_custom_contact_form',
    'access callback' => true,
  );
  return $items;
}

function gt_custom_contact_form() {
  return '';
}

function gt_custom_contact_form_title() {
  return t('Contact us');
}

And make that Webform available into a block from here: /node/nodeid/webform/configure

Advance settings -> Available as block

Now open block admin page, find that block, set Visibility settings to show that block on contact-us page only, make that block translatable using Make this block translatable.

Now language switcher block allow you to switch the languages.

And the main thing is Webform node will remain same.

4
  • Why use t in hook when webform is already i18n aware? And it was like that 3 years ago, certainly not a sudden change. -1 from me until you provide some explanation.
    – Mołot
    Commented Aug 17, 2015 at 12:48
  • 1
    Well, if you are that much confident that try to implement your own answer: If you have "localization by string translation" then it will create additional nodes each with their own title, path etc, but they will share a single webform. Use the translate tab just to change the node title etc, but to translate elements in the webform, go to /admin/config/regional/translate/translate and search of each field label etc in turn. Its not working at all. Even after adding translated strings(admin/config/regional/translate/translate) for each form labels, it shows labels in English only.
    – Parth Vora
    Commented Aug 17, 2015 at 12:56
  • And I clearly mentioned that I want to keep single node only.
    – Parth Vora
    Commented Aug 17, 2015 at 12:57
  • @Parth Vora that was my answer you're referencing but in response to someone else's comment. Commented Aug 17, 2015 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.