For those of you using WordPress that would like a non-intrusive simple way to add qTranslate support to your Contact Form 7 contact forms, here’s a simple snippet you can insert into functions.php:
// Add qTranslate support to contact form 7 add_filter('wpcf7_form_elements', 'rl_wpcf7_form_elements'); function rl_wpcf7_form_elements($content){ if(function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')){ return qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($content); } } add_filter('wpcf7_form_class_attr', 'rl_wpcf7_form_class_attr'); function rl_wpcf7_form_class_attr($content){ if(function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')){ return qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($content); } } add_filter('wpcf7_display_message', 'rl_wpcf7_display_message'); function rl_wpcf7_display_message($content){ // Split up our translations into an array $contentarray = explode('', $content); foreach($contentarray as $k=>$c){ // Reset the array keys with the language code $newkey = substr($c, 5, 2); $contentarray[$newkey] = str_replace('', '', $c); unset($contentarray[$k]); } unset($contentarray[0]); $url = str_replace($_SERVER['HTTP_ORIGIN'], '', $_SERVER['HTTP_REFERER']); $url = substr($url, 1, 2); // Return translated value, otherwise return english if(isset($contentarray[$url])){ return $contentarray[$url]; }else{ return $contentarray['en']; } }
This allows you to create multiple contact forms (one for each language) and use different shortcode for each tab created by qTranslate in your TinyMCE editor.