The Official How-To On Translating the Contact Form In Drupal 6.x

avantix - February 18, 2009 - 17:28

After hours of research, I've finally come up with a default core solution that I'd like to share with everyone on how to translate the Contact form module that comes with Drupal in Drupal 6.x.

Basic Instructions:

Make sure your Contact form module is enabled first, of course.

Go to drupal\modules\contact and open the file contact.pages.inc.
Go to line 41.

Replace the code...

$form['contact_information'] = array('#value' => filter_xss_admin(variable_get('contact_form_information', t('You can leave a message using the contact form below.'))));

...with:

$form['contact_information'] = array('#value' => t(filter_xss_admin(variable_get('contact_form_information', 'You can leave a message using the contact form below.'))));

Once replaced, save the page.
Next, install the module String Overrides.
Once installed, go to the String Overrides main page on your Drupal site under admin/settings/stringoverrides and click on the preferred language you would like to translate your contact form text to.
Make sure you originally replace "Contact" with the appropriate translation for "Contact" under your preferred language, and also for the text "You can leave a message using the contact form below." Keep in mind that if you have changed that text, then you should translate the text that you changed it to instead.

After all this has been done, you'll have a sweet translated contact form.

Fresh

avantix - February 18, 2009 - 19:39

Holla, ftw.

Are you sure this is the best

doomed - March 22, 2009 - 16:27

Are you sure this is the best way to do it?

It's hard to believe that to translate the contact form on Drupal 6 we have to go thru that.

Ok, I'm trying to do as you

doomed - March 22, 2009 - 17:39

Ok, I'm trying to do as you say.

This part i dont get - "Keep in mind that if you have changed that text, then you should translate the text you changed it with instead."

Can you explain?

Did i do something

doomed - March 22, 2009 - 17:47

Did i do something wrong?

First i changed the contact.pages.inc according to your post.

Then I added these lines to the settings.php file (just following some old instructions that used to work on D5).

$conf['i18n_variables'] = array(
'site_name',
'site_slogan',
'site_mission',
'site_footer',
'anonymous',
'contact_form_information',
);

I noticed the above form fields now show "This is a multilingual variable."

I seem to be able to translate site_name and others via Translate Interface.

But the stuff on contact_form_information is still not coming up on the Translate Interface search engine.

How do i fix this?

It's coming up now. I guess

doomed - March 22, 2009 - 18:34

It's coming up now.

I guess it takes a while to be fetched by the "Translate Interface" thing?

Solution

avantix - April 14, 2009 - 14:25

Hi Doomed,

Glad you figured it out.

To answer your questions...

When I say:

"'You can leave a message using the contact form below.' Keep in mind that if you have changed that text, then you should translate the text you changed it with instead."

That means, if you changed the text from the original text - "You can leave a message using the contact form below." - say, too, "Banana Splits Contact Form", then you want to change the translation for "Banana Splits Contact Form" instead.

Also, the variable adding in the array you did is not necessary. Just follow those instructions above for pure success.

Best -

We've implemented something similar to this

icanlocalize - April 15, 2009 - 16:50

We needed to support contact form localization in our translation module so we implemented something that resembles what you've suggested.

The good news are that to use it, you don't need to hack any file in any module. Our module replaces the functions that need updating. It also supports localizing the auto-reply email that the site sends and makes the contact form translation behave just like any other node that's being translated.

Here's a quick overview of how it works internally:
http://drupal-translation.com/node/90

You might be able to pull some ideas from that for your own implementation.

While you're at it, did you think about what you'll do with contacts in different languages once you get them?

Brilliant work.

avantix - April 16, 2009 - 19:04

icanlocalize,

Brilliant work. Looks great - haven't tested it out, but I'm glad there's finally a solution for this.

Best -

Great post, but ...

asiby - June 12, 2009 - 02:25

Guys, this solution is great. But we can keep it simple by simply doing the following replacement in the code

Replace this

<?php
...
$form['contact_information'] = array('#value' => filter_xss_admin(variable_get('contact_form_information', t('You can leave a message using the contact form below.'))));
...
?>

... with:

<?php
...
$form['contact_information'] = array('#value' => t(filter_xss_admin(variable_get('contact_form_information', 'You can leave a message using the contact form below.'))));
...
?>

Please note that after the replacement, the t() function will not be applied to the default value only. Instead, it will be applied to the return value of the filter_xss_admin() function. That return value can be the default string or any existing value and should be well enough.

This way, you will not need to start managing the contact form strings with the stringoverrides module. The content can be simply translated with Drupal core translation module.

Cheers

Asiby

Good solution

redwraith - June 24, 2009 - 00:51

It worked great for me. I noticed one thing though, I had to remove any colon from the end of my strings since the colons are evaluated in a different t() so any strings with colons wouldn't get translated. For example:

I was trying to translate this
Your email address:
to
Votre adresse de courriel:

Had to change it to the following, notice no colons.
Your email address
to
Votre adresse de courriel

A no-code way to translate contact information

chaps2 - June 29, 2009 - 16:11

You can use your settings.php file to cancel the contact form information message setting, thus avoiding module hacks and form overrides:

Look for the variable overrides section, uncomment as necessary and add the line:

<?php
'contact_form_information' => NULL,
?>

Then translate the original t()'d message ('You can leave a message using the contact form below.') using the string overrides section in settings.php, string overrides module or whatever method you prefer.

Another way...

abuda - July 10, 2009 - 15:09

Hacking core code is something we should all avoid due to problems that may arise during upgrades.

Just override the contact mail page form and reset the message.
Install the string overrides module, add your translation to the new message and voila!

For example, say our theme name is mytheme. Then place the following into your template.php file (remember to replace all mytheme occurences with your own theme's name):

function mytheme_theme(){
  return array(
    'contact_mail_page' => array(
      'arguments' => array('form' => NULL)
    ),
  );
}
function mytheme_contact_mail_page($form) {
  $form['contact_information']['#value'] = t('Howdy! Send me an angel asap...');
  return drupal_render($form);
}

Empty your cached data from the admin/settings/performance page.

Now on the string overrides module page, select the language (tab) you are translating into, enter the message above (i.e. Howdy! Send me an angel asap...) in the left textbox and on the right textbox its translation. Save configuration.

---

There is an easier way without using the string overrides module at all and which you may prefer. We can translate the additional information message of our contact form as usual however that translation isn't displayed when switching to the language in question. That's the problem.

From the contact form module page (admin/build/contact) under settings, enter your additional information message as usual or leave the default one as is. Then in your template.php file enter the following (remember to replace all mytheme occurences with your own theme's name):

function mytheme_theme(){
  return array(
    'contact_mail_page' => array(
      'arguments' => array('form' => NULL)
    ),
  );
}
function mytheme_contact_mail_page($form) {
$form['contact_information']['#value'] = t($form['contact_information']['#value']);
return drupal_render($form);
}

Empty your cached data from the admin/settings/performance page.
Now go to your Translate interface (admin/build/translate/search) and search for that string and translate it. Test it :-)

Hope that helps.

very good

zhaocai8 - July 18, 2009 - 17:52

very good

the theme template function

vthirteen - July 28, 2009 - 12:22

the theme template function works great, thank you

See also tcontact

kari.kaariainen - August 20, 2009 - 17:10

There is now a nice module based approach by haffmans at http://drupal.org/project/tcontact

 
 

Drupal is a registered trademark of Dries Buytaert.