Translation for Drupal contact forms
Drupal6 and its i18n module don't allow translation for contact forms. In this post, we'll explain how we've overcome this limitation and how ICanLocalize Translator provides multilingual contact forms in Drupal.
What works:
- Translate form labels, this can be done with the translate interface in Drupal 6
What doesn't work:
- Translate the welcome message, at the top of the contact form, which is by default "You can leave a message using the contact form below".
- Translate the categories shown in the category list box
- Translate the confirmation message, sent after the user submits the form.
Translating contact info and categories
To translate these we need to hook the form alter and use the t() function to use the translated text. Contact info is stored as a variable 'contact_form_information' and the categories can be obtained from $form['cid']['#options']. Values are written back using the t() function (Drupal's string translation).
function icl_content_alter_standard_contact_form(&$form, $form_state) {
global $language;
$contact_info = variable_get('contact_form_information', '');
if (strlen($contact_info) > 0) {
$form['contact_information']['#value'] = filter_xss_admin(t($contact_info));
}
if (isset($form['cid']['#options'])) {
foreach($form['cid']['#options'] as $index => $value) {
$form['cid']['#options'][$index] = t($value);
}
}
$block = locale_block('view');
$form['translation-links'] = array (
'#type' => 'markup',
'#value' => '<br><br>' . str_replace('<ul>', '<ul class="links inline">', $block['content']),
);
$form['#submit'][0] = 'icl_content_contact_mail_page_submit';
}
We also add a language switcher to the bottom of the form by calling local_block. We add the class="links inline" attribute to the language switcher so that it displays the same as language switchers in other nodes.
Translating the reply message
To use the translated reply messages we substitute Drupal's form submit function with our own submit function. This function is a duplicate of the contact_mail_page_submit function with the following changes:
// Load category properties and save form values for email composition.
$contact = contact_load($values['cid']);
$values['contact'] = $contact;
We use Drupal's t() function to send the translated confirmation message:
// Load category properties and save form values for email composition.
$contact = contact_load($values['cid']);
if (strlen($contact['reply']) > 0) {
$contact['reply'] = t($contact['reply']);
}
$values['contact'] = $contact;
With these changes all the text on the contact form can be translated using the translate interface.
Our ICanLocalize module includes this and additionally:
- Collects all the untranslated text and sends it to translation in one go.
- The contact form is translated in the same manner as a node. Users can select it from the Translation dashboard and send to translation without bothering with internal implementation.
- Translations received from the ICanLocalize server are automatically saved to the locale_target database table, there is no need to search for strings in the translate interface.
Back and forth translation for the submitted contact forms
Once Drupal sites include multilingual contact forms, visitors start sending messages in their own languages. Our statistics show that almost all contacts are made in the language the contact form is displayed in.
Right now, people use either free machine translation (which sometimes gives readable results and sometimes not) or use our instant text translation for accurate professional translation. It works fine, but we want to make communication with your visitors even more streamlined.
Visitor communication translation inside the contact form
The next step will be to add full multilingual customer communication to the contact form.
This will allow visitors to communicate in their languages and website owners to respond in their languages. All translation will take place behind the scenes.
The way it's going to work is:
- Messages from customers will be translated to the website owner's language using a free machine translation.
- In most cases, translation allows understanding the message. Site owner can have unclear messages to professionally translated.
- Any messages from the website owner will be written in his native language and will be professionally translated before being sent to the visitor.

Comments
thanks
Thank you very much very nice article
Great information! Very useful for me. Thanks a lot.
The idea is awesome. Congrats.
Thanks for the review! It
Thanks for the review! It would be nice if you could pour the feedback to the relevant issues, so they will get to the places where they belong. Some feedback:
Usability / User Interface: well, please submit your first chunk of comments on the node translation issue, let's see what others think. The help texts definitely need an update, some our outdated. That will be fixed after the code freeze, once functionality settled. The "text group" section is supposed to be understandable because on a stock Drupal site, you would have at least "site settings" and "content types" text groups by default additionaly to the built in textgroup there now. That would only happen if people review the dynamic object translation patch, and we manage to get it in. Time is tight.
Language Switcher block: please comment on the issue.
Node Translation: this is important feedback, which should be posted on the issue.
Custom Content Type Translation: this is only going to happen if the basics on dynamic object translation are settled wireless internet service. There is no such functionality yet, so it is no surprise that you don't see it.
Site Information Translation: see the previous point.
Contact Form Translation: see the previous point.
Language Negotiation: this is a bug, would be nice to submit a new issue.
Thanks so much for this! I
Thanks so much for this! I was looking for a way to translate my site, and this gets me almost all of the way there.
Post new comment