The Contact Form 7 for WordPress is a nice simple plugin to build contact forms fast. But when it comes to making it completely multilingual it lacks a bit.
I am currently creating a website with 13 different languages, that would mean to create the same contact form 13 times, not really practical :)
I am translating the form labels on the fly with some javascript magic, but for the messages I had to go a bit deeper.
- Open wp-content/plugins/contact-form-7/classes.php
- Go to line 800 function message
- Change this
12345678public function message( $status ) {$messages = $this->messages;$message = isset( $messages[$status] ) ? $messages[$status] : '';$message = $this->replace_mail_tags( $message, true );return apply_filters( 'wpcf7_display_message', $message, $status);}
to this
12345678public function message( $status ) {$messages = $this->messages;$message = isset( $messages[$status] ) ? $messages[$status] : '';$message = $this->replace_mail_tags( $message, true );return __(apply_filters( 'wpcf7_display_message', $message, $status ),'textdomain');}
See how I wrapped the gettext function for the return, that does all the magic. - Next we have to make sure that the messages are being found by localization helpers like Codestyling Localization
- In your theme functions.php add a translation for each of the Contact 7 Form messages
- The first message in the Contact 7 Form admin says: Your message was sent successfully. Thanks.
12345$contact_form_msgs = array('msg_1' => __('Your message was sent successfully. Thanks.','textdomain'),'msg_2' => __('Failed to send your message. Please try later or contact the administrator by another method.','textdomain'),'msg_3' => __('Validation errors occurred. Please confirm the fields and submit it again.','textdomain'),);
- Do not change these messages in the Contact 7 Form admin anymore or the setup will break. These updates will have to be repeated with each plugin update, unless the author does something similar.
- Happy translating.
Cheers
Alex