I have managed to localize my clients site from Spanish to French:
http://www.microcementoeuropeo.com
…using a combination of the WPML plugin and the Gettext framework. The only thing i have been unsuccessful translating are the labels on the contact form itslef:
<p>Nombre<br />
<span class="wpcf7-form-control-wrap your-name"><input type="text" name="your-name" value="" class="wpcf7-text wpcf7-validates-as-required" size="40" /></span> </p>
<p>Email<br />
<span class="wpcf7-form-control-wrap your-email"><input type="text" name="your-email" value="" class="wpcf7-text wpcf7-validates-as-email wpcf7-validates-as-required" size="40" /></span> </p>
<p>Teléfono<br />
…so the text i’m trying to translate would be “Nombre” – to the French.
I’ve tried the gettext methods that worked for other hard-coded areas:
<p><?php _e('Nombre', theme_domain);?><br />
<p><?php __('Nombre', theme_domain);?><br />
…but this does not work.
(i´m adding these into wordpress through admin and not directly to the .php file).
I’m familiar with creating .po / .mo files and know how to localize normal hard-coded text – but contact form 7 has me baffled.
Any suggestions appreciated.
You don’t need any of that. Check the link below specially the secition “Creating contact form in different languages”
contact form in your language
I think the solution to your problem lies in the ability to run PHP within the Contact Form 7 template. You can do this by writing your own shortcode and then adding this into CF7.
Firstly, setup a shortcode so your translation functions are available within WP content areas. Something like:
(disclaimer: I haven’t tested this!)
Then you can use a plugin like this one so you can add shortcodes to the CF7 template area. With this plugin you have to define the codes you want to use as ‘keys’, something like:
Then you should be able to use e_text shortcode in the CF7 form template and email templates.
Thanks for the suggestion JunkMyFunk. I tried to implement this but ran into some issues.
I eventually found a workaround using the following method:
Use the following conditional statement to show the correct contact form for each language.
Thanks for your help all the same –
The reason why this does not work is because as of v4.4.1 the CF7 plugin does not include language locales anymore, these are maintained in the worpdress translation GlotPress instead. As a result, you need to install locales manually, one for each language you want to create forms for. You can then create a form in a new language by adding the
locale
attribute in your dashboard url, for example for the German locale de_DE,http://<your-domain>/wp-admin/admin.php?page=wpcf7-new&locale=de_DE
Alternatively, you can use the CF7 PolyLang module which allows you to manage CF7 forms in different languages using the PolyLang plugin (recommended by WP). PolyLang is an alternative to WPML,